public Session(PeerSession s, X509Certificate2 nodeCert) { logger = new SessionLogger(this); this.Id = s.Id; this.Kind = s.Kind; this.Budget = s.Budget; this.FromNode = s.FromNode; this.ToNode = s.ToNode; this.TaskId = s.TaskId; this.GuidKey = System.Guid.NewGuid().ToByteArray(); this.Secret = s.Secret; //myKeyPairCrypto = csp; cert = nodeCert; AuthenticatedEvent = new ManualResetEvent(false); if (this.Kind == SessionType.Store) { this.Budget = 0; // bug?? do we have to initialize to 0 when receiving/storing? // client-side flags are not relevant here since the client data processing is not initialized by the Session. if (s.Flags.HasFlag(DataProcessingFlags.CChecksum)) { s.Flags ^= DataProcessingFlags.CChecksum; } if (s.Flags.HasFlag(DataProcessingFlags.CCompress)) { s.Flags ^= DataProcessingFlags.CCompress; } if (s.Flags.HasFlag(DataProcessingFlags.CDedup)) { s.Flags ^= DataProcessingFlags.CDedup; } if (s.Flags.HasFlag(DataProcessingFlags.CEncrypt)) { s.Flags ^= DataProcessingFlags.CEncrypt; } this.Flags = s.Flags; pipeline = new Node.DataProcessing.DataPipeline(Node.DataProcessing.PipelineMode.Read, this.Flags); logger.Log(Severity.DEBUG, "Creating storage session (" + this.Kind.ToString() + ") with client node #" + this.FromNode.Id + " (" + this.FromNode.IP + ":<UNAVAILABLE>)"); } else if (this.Kind == SessionType.Backup) { this.CryptoKey = System.Guid.NewGuid().ToByteArray(); logger.Log(Severity.DEBUG, "Creating client session #" + this.Id + " with storage node #" + this.ToNode.Id + " (" + this.ToNode.IP + ":" + this.ToNode.ListenPort + ")"); } }
internal ChunkProcessor(Session session, DataPipeline p, Backup b, CancellationToken t) { backup = b; pipeline = p; storageSession = session; token = t; BinaryFormatter formatter = new BinaryFormatter(); BChunkHeader header = new BChunkHeader(); header.DataFlags = pipeline.Flags; header.Version = Utilities.PlatForm.Instance().NodeVersion; header.TaskId = session.TaskId; header.OwnerNode = b.NodeId; MemoryStream headerStream = new MemoryStream(); formatter.Serialize(headerStream, header); headerData = headerStream.ToArray(); // end-of-chain stream sessionDataStream = new NetworkStream(storageSession.DataSocket); p.OutputStream = sessionDataStream; p.Init(); }