コード例 #1
0
        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 + ")");
            }
        }
コード例 #2
0
        /// <summary>
        /// Connects to client2
        /// </summary>
        public void Connect()
        {
            Logger.Append(Severity.DEBUG, "Trying to start connection to node " + this.ToNode.IP + ", port " + this.ToNode.ListenPort);
            IPAddress  addr = IPAddress.Parse(this.ToNode.IP);
            IPEndPoint dest = new IPEndPoint(addr, this.ToNode.ListenPort);

            // 1- Opening control socket
            clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            IAsyncResult result = clientSocket.BeginConnect(dest, null, null);

            result.AsyncWaitHandle.WaitOne(10000, true);            //not connected after 10s means storage node too slow of unavailable
            if (!clientSocket.Connected)
            {
                throw new Exception("Could not connect message socket");
            }


            // 2- Opening data socket
            dataSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            /*if(ConfigManager.GetValue("STDSOCKBUF") == null){
             *      dataSocket.SendBufferSize = 512*1024; //512k
             * }*/
            /*else{
             *      try{
             *              dataSocket.NoDelay = false;
             *              clientSocket.SendBufferSize = 0;
             *              clientSocket.NoDelay = true;
             *      }
             *      catch{} // NoDelay doesn't seem to be supported on FreeBSD
             * }*/
            dataSocket.SendTimeout = 120000;
            result = dataSocket.BeginConnect(dest, null, null);
            result.AsyncWaitHandle.WaitOne(10000, true);
            if (!dataSocket.Connected)
            {
                throw new Exception("Could not connect data socket");
            }
            StartListening(false);
            SendDigitalSignature();
            logger.Log(Severity.INFO, "Opened 1 session with storage node #" + this.ToNode.Id);
        }
コード例 #3
0
ファイル: Session.cs プロジェクト: danilogr/TUX
 void Started()
 {
     SaveSessionData();
     SessionLogger.Log(this);
 }