/// <summary>
        /// Initializes a new instance of the <see cref="Distribox.Network.AntiEntropyProtocol"/> class.
        /// </summary>
        /// <param name="listeningPort">Listening port.</param>
        /// <param name="peerFileName">Peer file name.</param>
        /// <param name="versionControl">Version control.</param>
        public AntiEntropyProtocol(int listeningPort, string peerFileName, VersionControl versionControl)
        {
            // Initialize version control
            this.versionControl = versionControl;

            // Initialize peer list
            this.peers = PeerList.GetPeerList(peerFileName);
            this.listeningPort = listeningPort;

            // Initialize listener
            this.listener = new AtomicMessageListener(listeningPort);
            this.listener.OnReceive += this.OnReceiveMessage;

            // Initialize timer to connect other peers periodically
            System.Timers.Timer timer = new System.Timers.Timer(Config.ConnectPeriodMs);
            timer.Elapsed += this.OnTimerEvent;
            timer.AutoReset = true;
            timer.Enabled = true;

            // Initialize request manager
            this.requestManager = new RequestManager();

            // Initialize Protocol message factory
            this.messageFactory = new ProtocolMessageFactory();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Distribox.Network.AntiEntropyProtocol"/> class.
        /// </summary>
        /// <param name="listeningPort">Listening port.</param>
        /// <param name="peerFileName">Peer file name.</param>
        /// <param name="versionControl">Version control.</param>
        public AntiEntropyProtocol(int listeningPort, string peerFileName, VersionControl versionControl)
        {
            // Initialize version control
            this.versionControl = versionControl;

            // Initialize peer list
            this.peers         = PeerList.GetPeerList(peerFileName);
            this.listeningPort = listeningPort;

            // Initialize listener
            this.listener            = new AtomicMessageListener(listeningPort);
            this.listener.OnReceive += this.OnReceiveMessage;

            // Initialize timer to connect other peers periodically
            System.Timers.Timer timer = new System.Timers.Timer(Config.ConnectPeriodMs);
            timer.Elapsed  += this.OnTimerEvent;
            timer.AutoReset = true;
            timer.Enabled   = true;

            // Initialize request manager
            this.requestManager = new RequestManager();

            // Initialize Protocol message factory
            this.messageFactory = new ProtocolMessageFactory();
        }
Esempio n. 3
0
        public void Test()
        {
            AtomicMessageListener listener = new AtomicMessageListener(1234);
            listener.OnReceive += this.OnReceiveHandler;

            AtomicMessageSender sender = new AtomicMessageSender(new Peer("127.0.0.1", 1234));

            byte[] message = { 1, 2, 43, 23 };
            this.lastData = message;
            this.lastPeerFrom = new Peer("127.0.0.1", -1);
            this.received = false;
            sender.SendBytes(message);

            Thread.Sleep(3);
        }