Exemplo n.º 1
0
        public P2PConnection(P2PConfiguration configuration, IEnumerable <IPEndPoint> nodes, int min, int max)
        {
            server = new Server(configuration);
            server.OnClientAuthenticated += OnClientAuthenticated;
            discovery = new DiscoveryProtocol
            {
                OnServerPort    = HandleServerPort,
                OnEndPointTable = HandleEndPointTable,
                OnPing          = HandlePing,
                OnPong          = HandlePong
            };

            certificate = configuration.Certificate;

            // todo GetNode(configuration.IPEndpoint)
            var self = new Persona(certificate);

            nodeManager        = new NodeManager(self, configuration.IPEndpoint, configuration.ForwardedPort, nodes);
            peerManager        = new PeerManager();
            nodeStorage        = new NodeStorage(logger);
            connectionsManager = new ConnectionsManager(min, max);
            timer = new Timer(OnTick, null, Timeout.Infinite, Timeout.Infinite);

            peerManager.OnPeerConnected = peer =>
            {
                connectionsManager.NewConnection();
                onConnected.Call(peer);
            };
            peerManager.OnPeerDisconnected = peer =>
            {
                connectionsManager.PeerDisconnected();
            };
            peerManager.OnReceived = (peer, channel, message) =>
            {
                OnReceived(peer, GetChannel(channel), message);
            };

            DISCOVER_CHANNEL = CreateChannel(0);
        }
Exemplo n.º 2
0
 public Server(P2PConfiguration configuration)
 {
     this.configuration = configuration;
     listener           = new TcpListener(configuration.IPEndpoint);
 }