Example #1
0
        /// <summary>
        /// Creates the peer address based on the network discovery that was done./>
        /// </summary>
        /// <param name="peerId">The ID of this peer.</param>
        /// <param name="channelClientConfiguration"></param>
        /// <param name="channelServerConfiguration"></param>
        /// <returns>The peer address of this peer.</returns>
        private static PeerAddress FindPeerAddress(Number160 peerId,
                                                   ChannelClientConfiguration channelClientConfiguration, ChannelServerConfiguration channelServerConfiguration)
        {
            string status = DiscoverNetworks.DiscoverInterfaces(channelClientConfiguration.BindingsOutgoing);

            Logger.Info("Status of external address search: " + status);

            IPAddress outsideAddress = channelClientConfiguration.BindingsOutgoing.FoundAddress;

            if (outsideAddress == null)
            {
                throw new IOException("Not listening to anything. Maybe the binding information is wrong.");
            }

            var peerSocketAddress = new PeerSocketAddress(outsideAddress,
                                                          channelServerConfiguration.Ports.TcpPort,
                                                          channelServerConfiguration.Ports.UdpPort);

            var self = new PeerAddress(peerId, peerSocketAddress,
                                       channelServerConfiguration.IsBehindFirewall,
                                       channelServerConfiguration.IsBehindFirewall,
                                       false, PeerAddress.EmptyPeerSocketAddresses);

            return(self);
        }
Example #2
0
        /// <summary>
        /// Sets parameters and starts network device discovery.
        /// </summary>
        /// <param name="channelServerConfiguration">The server configuration that contains e.g. the handlers</param>
        /// <param name="dispatcher">The shared dispatcher.</param>
        /// <param name="peerStatusListeners">The status listeners for offline peers.</param>
        public ChannelServer(ChannelServerConfiguration channelServerConfiguration, Dispatcher dispatcher,
                             IList <IPeerStatusListener> peerStatusListeners)
        {
            ChannelServerConfiguration = channelServerConfiguration;
            _interfaceBindings         = channelServerConfiguration.BindingsIncoming;
            _dispatcher          = dispatcher;
            _peerStatusListeners = peerStatusListeners;
            string status = DiscoverNetworks.DiscoverInterfaces(_interfaceBindings);

            Logger.Info("Status of interface search: {0}.", status);

            _tcpDropConnectionInboundHandler = new DropConnectionInboundHandler(channelServerConfiguration.MaxTcpIncomingConnections);
            _udpDropConnectionInboundHandler = new DropConnectionInboundHandler(channelServerConfiguration.MaxUdpIncomingConnections);
            _udpDecoderHandler = new TomP2PSinglePacketUdp(channelServerConfiguration.SignatureFactory);
            _tcpDecoderHandler = new TomP2PCumulationTcp(channelServerConfiguration.SignatureFactory);
            _encoderHandler    = new TomP2POutbound(false, channelServerConfiguration.SignatureFactory);
        }