public ClientEngine(EngineSettings settings, PeerListener listener, PieceWriter writer, string peerId = null) { Check.Settings(settings); Check.Listener(listener); Check.Writer(writer); this.listener = listener; this.settings = settings; if (settings.FastResumePath != null && File.Exists(settings.FastResumePath)) { var encodedListData = File.ReadAllBytes(settings.FastResumePath); var encodedList = (BEncodedList)BEncodedValue.Decode(encodedListData); _fastResume = encodedList.Cast <BEncodedDictionary>() .Select(x => new FastResume(x)); } connectionManager = new ConnectionManager(this); RegisterDht(new NullDhtEngine()); diskManager = new DiskManager(this, writer); listenManager = new ListenManager(this); MainLoop.QueueTimeout(TimeSpan.FromMilliseconds(TickLength), () => { if (IsRunning && !disposed) { LogicTick(); } return(!disposed); }); torrents = new List <TorrentManager>(); torrentsReadonly = new ReadOnlyCollection <TorrentManager>(torrents); CreateRateLimiters(); this.peerId = peerId ?? GeneratePeerId(); localPeerListener = new LocalPeerListener(this); localPeerManager = new LocalPeerManager(); LocalPeerSearchEnabled = SupportsLocalPeerDiscovery; listenManager.Register(listener); // This means we created the listener in the constructor if (listener.Endpoint.Port == 0) { listener.ChangeEndpoint(new IPEndPoint(IPAddress.Any, settings.ListenPort)); } }
public ClientEngine(EngineSettings settings, PeerListener listener, PieceWriter writer, string peerId = null) { Check.Settings(settings); Check.Listener(listener); Check.Writer(writer); this.listener = listener; this.settings = settings; if (settings.FastResumePath != null && File.Exists(settings.FastResumePath)) { var encodedListData = File.ReadAllBytes(settings.FastResumePath); var encodedList = (BEncodedList) BEncodedValue.Decode(encodedListData); _fastResume = encodedList.Cast<BEncodedDictionary>() .Select(x => new FastResume(x)); } connectionManager = new ConnectionManager(this); RegisterDht(new NullDhtEngine()); diskManager = new DiskManager(this, writer); listenManager = new ListenManager(this); MainLoop.QueueTimeout(TimeSpan.FromMilliseconds(TickLength), () => { if (IsRunning && !disposed) LogicTick(); return !disposed; }); torrents = new List<TorrentManager>(); torrentsReadonly = new ReadOnlyCollection<TorrentManager>(torrents); CreateRateLimiters(); this.peerId = peerId ?? GeneratePeerId(); localPeerListener = new LocalPeerListener(this); localPeerManager = new LocalPeerManager(); LocalPeerSearchEnabled = SupportsLocalPeerDiscovery; listenManager.Register(listener); // This means we created the listener in the constructor if (listener.Endpoint.Port == 0) listener.ChangeEndpoint(new IPEndPoint(IPAddress.Any, settings.ListenPort)); }
public ClientEngine(EngineSettings settings, PeerListener listener, string peerId = null) : this(settings, listener, new DiskWriter(), peerId) { }
public void Unregister(PeerListener listener) { listener.ConnectionReceived -= ConnectionReceived; }
public void Register(PeerListener listener) { listener.ConnectionReceived += ConnectionReceived; }