private void OnTcpMessagePeek(ITcpSession session, Message message) { ElasticAddress address = message.Value <string>("enode"); // verify message PrivateKey nodeKey = MasterKey.CKD($"{address.Host}:{address.Port}"); if (!message.Verify(nodeKey.Address)) { Logger.warning("Unverified message"); return; } // valid address? if (nodeKey.Address != address.Address) { Logger.warning("Invalid address"); return; } Message msg = new Message.Builder() .Body(ACTION, ACTION_PEEK) .Body("peers", Peers.Count) .Build(MasterKey); session?.Write(msg.ToBytes()); }
public void SyncPeers(ITcpSession session, string[] catalogs) { Message message = new Message.Builder() .Body(ACTION, ACTION_UPDATE) .Body("peers", catalogs) .Build(MasterKey); session?.Write(message.ToBytes()); }
private void Register(ITcpSession session) { Message message = new Message.Builder() .Body(ACTION, ACTION_REGISTER) .Body("enode", NodeUrl.ToString()) .Build(NodeKey); session?.Write(message.ToBytes()); }
public void OnTransportRead(ITcpSession session, ref WrappedReader reader, WrappedArgs args) { List <ReadOnlySequence <byte> > buffers = (List <ReadOnlySequence <byte> >)args.Value; for (int i = 0; i < buffers.Count; i++) { session.Write(SocketConfig.message); } session.FlushAsync().NoAwait(); }
public async Task Respond(IHttpResponse response) { if (!response.IsValid) { throw new InvalidHttpResponseException(response.Validation); } if (_session.State == TcpSessionState.Closed) { throw new TcpSessionNotActiveException(); } var http = response.ToHttp(); await _session.Write(http, _token); }
public void SendTo(ITcpSession session, byte[] data) { session.Write(data); }
public int Send(byte[] data) { return(Ready ? _session.Write(data) : -1); }
private void OnStartSend() { _session.Write(common.SocketConfig.message); _session.FlushAsync().NoAwait(); }