/// <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();
        }
示例#2
0
        /// <summary>
        /// Starts the peer service.
        /// </summary>
        /// <param name='port'>
        /// Listening port of the peer.
        /// </param>
        private static void StartPeer(int port)
        {
            string peerListName = Config.PeerListFilePath;

            // Initialize anti entropy protocol
            var vs = new VersionControl();
            protocol = new AntiEntropyProtocol(port, peerListName, vs);

            // Initialize file watcher
            FileWatcher watcher = new FileWatcher();
            watcher.Created += vs.Created;
            watcher.Changed += vs.Changed;
            watcher.Deleted += vs.Deleted;
            watcher.Renamed += vs.Renamed;
            watcher.Idle += vs.Flush;
        }
 public void GetFileByNameTest()
 {
     var vc = new VersionControl();
     byte[] bytes = VersionControl.CreateFileBundle(this.list.SelectMany(x => x.History).ToList());
     List<FileEvent> receive = vc.AcceptFileBundle(bytes);
     vc.VersionList.GetFileByName("TT");
     vc.VersionList.GetFileById("2");
     vc.VersionList.RemoveFileByName("TT");
 }
        public void Test()
        {
            byte[] bytes = VersionControl.CreateFileBundle(this.list.First().History);

            var vc = new VersionControl();

            List<FileEvent> receive = vc.AcceptFileBundle(bytes);
        }
 public void CheckOutTest()
 {
     var vc = new VersionControl();
     byte[] bytes = VersionControl.CreateFileBundle(this.list.SelectMany(x => x.History).ToList());
     List<FileEvent> receive = vc.AcceptFileBundle(bytes);
     vc.CheckOut("2", "5");
 }