/// <summary> /// Creates a dispatcher. /// </summary> /// <param name="p2PId">The P2P ID the dispatcher is looking for incoming messages.</param> /// <param name="peerBeanMaster"></param> /// <param name="heartBeatMillis"></param> public Dispatcher(int p2PId, PeerBean peerBeanMaster, int heartBeatMillis) { _p2PId = p2PId; _peerBeanMaster = peerBeanMaster; _heartBeatMillis = heartBeatMillis; //Logger.Info("Instantiated with object identity: {0}.", RuntimeHelpers.GetHashCode(this)); }
public DirectResponder(Dispatcher dispatcher, PeerBean peerBeanMaster, ChannelHandlerContext ctx, Message.Message requestMessage) { _dispatcher = dispatcher; _peerBeanMaster = peerBeanMaster; _ctx = ctx; _requestMessage = requestMessage; }
public DistributedRouting(PeerBean peerBean, NeighborRpc neighbors) { _neighbors = neighbors; _peerBean = peerBean; // stable random number: no need to be truly random _rnd = new Random(peerBean.ServerPeerAddress.PeerId.GetHashCode()); }
/// <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; }
/// <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()); } }
/// <summary> /// Creates a slave peer that will attach itself to a master peer. /// </summary> /// <param name="parent">The parent peer.</param> /// <param name="peerId">The ID of this peer.</param> /// <param name="keyPair">The key pair or null.</param> public PeerCreator(PeerCreator parent, Number160 peerId, KeyPair keyPair) { parent._childConnections.Add(this); ConnectionBean = parent.ConnectionBean; PeerBean = new PeerBean(keyPair); PeerAddress self = parent.PeerBean.ServerPeerAddress.ChangePeerId(peerId); PeerBean.SetServerPeerAddress(self); _master = false; }
/// <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)); }
/// <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)); }
/// <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()); }
/// <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; }
public DirectDataRpc(PeerBean peerBean, ConnectionBean connectionBean) : base(peerBean, connectionBean) { Register(Rpc.Commands.DirectData.GetNr()); }
public BroadcastRpc(PeerBean peerBean, ConnectionBean connectionBean, IBroadcastHandler broadcastHandler) : base(peerBean, connectionBean) { Register(Rpc.Commands.Broadcast.GetNr()); BroadcastHandler = broadcastHandler; }
public NeighborRpc(PeerBean peerBean, ConnectionBean connectionBean) : this(peerBean, connectionBean, true) { }