Esempio n. 1
0
        /// <summary>
        /// Creates a master peer and starts UDP and TCP channels.
        /// </summary>
        /// <param name="p2PId">The ID of the network.</param>
        /// <param name="peerId">The ID of this peer.</param>
        /// <param name="keyPair">The key pair or null.</param>
        /// <param name="channelServerConfiguration">The server configuration to create the
        /// channel server that is used for listening for incoming connections.</param>
        /// <param name="channelClientConfiguration">The client-side configuration.</param>
        /// <param name="timer"></param>
        public PeerCreator(int p2PId, Number160 peerId, KeyPair keyPair,
                           ChannelServerConfiguration channelServerConfiguration,
                           ChannelClientConfiguration channelClientConfiguration,
                           ExecutorService timer)
        {
            // peer bean
            PeerBean = new PeerBean(keyPair);
            PeerAddress self = FindPeerAddress(peerId, channelClientConfiguration, channelServerConfiguration);

            PeerBean.SetServerPeerAddress(self);
            Logger.Info("Visible address to other peers: {0}.", self);

            // start server
            var dispatcher    = new Dispatcher(p2PId, PeerBean, channelServerConfiguration.HearBeatMillis);
            var channelServer = new ChannelServer(channelServerConfiguration, dispatcher, PeerBean.PeerStatusListeners);

            if (!channelServer.Startup())
            {
                ShutdownNetty();
                throw new IOException("Cannot bind to TCP or UDP port.");
            }

            // connection bean
            var sender      = new Sender(peerId, PeerBean.PeerStatusListeners, channelClientConfiguration, dispatcher);
            var reservation = new Reservation(channelClientConfiguration);

            ConnectionBean = new ConnectionBean(p2PId, dispatcher, sender, channelServer, reservation, channelClientConfiguration, timer);
            _master        = true;
        }
Esempio n. 2
0
 /// <summary>
 /// Setup the RPC and register for incoming messages.
 /// </summary>
 /// <param name="peerBean">The peer bean.</param>
 /// <param name="connectionBean">The connection bean.</param>
 /// <param name="register">Whether incoming messages should be registered.</param>
 public NeighborRpc(PeerBean peerBean, ConnectionBean connectionBean, bool register)
     : base(peerBean, connectionBean)
 {
     if (register)
     {
         Register(Rpc.Commands.Neighbor.GetNr());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a request handler that can send TCP and UDP messages.
        /// </summary>
        /// <param name="tcsResponse">The future that will be called when we get an answer.</param>
        /// <param name="peerBean">The peer bean.</param>
        /// <param name="connectionBean">The connection bean.</param>
        /// <param name="configuration">The client-side connection configuration.</param>
        public RequestHandler(TaskCompletionSource<Message.Message> tcsResponse, PeerBean peerBean, ConnectionBean connectionBean, IConnectionConfiguration configuration)
        {
            _tcsResponse = tcsResponse;
            PeerBean = peerBean;
            ConnectionBean = connectionBean;
            _message = tcsResponse.Task.AsyncState as Message.Message;
            _sendMessageId = new MessageId(_message);
            IdleTcpSeconds = configuration.IdleTcpSeconds;
            IdleUdpSeconds = configuration.IdleUdpSeconds;
            ConnectionTimeoutTcpMillis = configuration.ConnectionTimeoutTcpMillis;

            //Logger.Info("Instantiated with object identity: {0}.", RuntimeHelpers.GetHashCode(this));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a request handler that can send TCP and UDP messages.
        /// </summary>
        /// <param name="tcsResponse">The future that will be called when we get an answer.</param>
        /// <param name="peerBean">The peer bean.</param>
        /// <param name="connectionBean">The connection bean.</param>
        /// <param name="configuration">The client-side connection configuration.</param>
        public RequestHandler(TaskCompletionSource <Message.Message> tcsResponse, PeerBean peerBean, ConnectionBean connectionBean, IConnectionConfiguration configuration)
        {
            _tcsResponse               = tcsResponse;
            PeerBean                   = peerBean;
            ConnectionBean             = connectionBean;
            _message                   = tcsResponse.Task.AsyncState as Message.Message;
            _sendMessageId             = new MessageId(_message);
            IdleTcpSeconds             = configuration.IdleTcpSeconds;
            IdleUdpSeconds             = configuration.IdleUdpSeconds;
            ConnectionTimeoutTcpMillis = configuration.ConnectionTimeoutTcpMillis;

            //Logger.Info("Instantiated with object identity: {0}.", RuntimeHelpers.GetHashCode(this));
        }
Esempio n. 5
0
 /// <summary>
 /// Constructor that registers this RPC with the message handler.
 /// </summary>
 /// <param name="peerBean">The peer bean.</param>
 /// <param name="connectionBean">The connection bean.</param>
 public QuitRpc(PeerBean peerBean, ConnectionBean connectionBean)
     : base(peerBean, connectionBean)
 {
     Register(Rpc.Commands.Quit.GetNr());
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a handler with a peer bean and a connection bean.
 /// </summary>
 /// <param name="peerBean">The peer bean.</param>
 /// <param name="connectionBean">The connection bean.</param>
 protected DispatchHandler(PeerBean peerBean, ConnectionBean connectionBean)
 {
     PeerBean = peerBean;
     ConnectionBean = connectionBean;
 }
Esempio n. 7
0
 public DirectDataRpc(PeerBean peerBean, ConnectionBean connectionBean)
     : base(peerBean, connectionBean)
 {
     Register(Rpc.Commands.DirectData.GetNr());
 }
Esempio n. 8
0
 public BroadcastRpc(PeerBean peerBean, ConnectionBean connectionBean, IBroadcastHandler broadcastHandler)
     : base(peerBean, connectionBean)
 {
     Register(Rpc.Commands.Broadcast.GetNr());
     BroadcastHandler = broadcastHandler;
 }
Esempio n. 9
0
 public NeighborRpc(PeerBean peerBean, ConnectionBean connectionBean)
     : this(peerBean, connectionBean, true)
 { }