private bool StartRemoteService() { bool bRet = false; _remoteMessageHandler = new PeerServices(); _remoteHost = new ServiceHost(_remoteMessageHandler); //To handle the remote traffic _remoteMessageHandler.OnRemoteEnergyRequest += new manageEnergyRequest(ManageRemoteEnergyRequest); _remoteMessageHandler.OnRemoteEnergyReply += new replyEnergyRequest(ManageRemoteEnergyReply); _remoteMessageHandler.OnRemotePeerIsDown += new remotePeerIsDown(RemotePeerIsDown); try { _remoteHost.Open(); bRet = true; XMLLogger.WriteRemoteActivity("Remote service started."); } catch (Exception e) { XMLLogger.WriteErrorMessage(this.GetType().FullName.ToString(), "Unable to start Remote Service."); //XMLLogger.WriteErrorMessage(this.GetType().FullName.ToString(), e.ToString()); //For debug purpose _remoteHost.Abort(); } return(bRet); }
public byte[] PortBytes; // 2 bytes public BitcoinNetworkAddressPayload(DateTimeOffset timestamp, PeerServices peerServices, IPAddress ipAddress, int port) { this.Timestamp = timestamp; this.PeerServices = peerServices; this.IPAddress = ipAddress; this.Port = port; this.TimeBytes = BitConverter.GetBytes((uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds()); this.PeerServicesBytes = BitConverter.GetBytes((ulong)this.PeerServices); byte[] ipBytes = ipAddress.GetAddressBytes(); if (ipBytes.Length == 16) { this.IPBytes = ipBytes; } else if (ipBytes.Length == 4) { this.IPBytes = new byte[16]; Buffer.BlockCopy(ipBytes, 0, this.IPBytes, 12, 4); this.IPBytes[10] = 0xff; this.IPBytes[11] = 0xff; } else { throw new ArgumentException("ipAddress"); } var portBytes = BitConverter.GetBytes((ushort)port); this.PortBytes = new byte[2]; // swap to get network byte order this.PortBytes[0] = portBytes[1]; this.PortBytes[1] = portBytes[0]; }
public byte[] UserAgentBytes; // varstring public BitcoinVersionPayload(BitcoinVarString userAgent, byte[] nonceBytes, BitcoinNetworkAddressPayload sender, BitcoinNetworkAddressPayload receiver) { this.ProtocolVersion = ChatClientConfiguration.ProtocolVersion; this.ProtocolVersionBytes = BitConverter.GetBytes(ChatClientConfiguration.ProtocolVersion); this.Services = ChatClientConfiguration.OwnPeerServices; this.ServicesBytes = BitConverter.GetBytes((ulong)this.Services); this.TimeStamp = DateTimeOffset.UtcNow; this.TimestampBytes = BitConverter.GetBytes((ulong)this.TimeStamp.ToUnixTimeSeconds()); this.Sender = sender; this.SenderAddressBytes = sender.SerializeForVersion(); this.Receiver = receiver; this.ReceiverAddressBytes = receiver.SerializeForVersion(); this.NonceBytes = nonceBytes; this.UserAgent = userAgent; this.UserAgentBytes = userAgent.VarStringBytes; this.StartHeightBytes = new byte[4]; this.StartHeight = BitConverter.ToUInt32(this.StartHeightBytes, 0); this.RelayBytes = new byte[1]; this.RelayBytes[0] = 1; }
public BitcoinNetworkAddressPayload(byte[] serialized, int startIndex, bool hasTimeStamp) { if (hasTimeStamp) { var time = BitConverter.ToUInt32(serialized, startIndex); this.Timestamp = DateTimeOffset.FromUnixTimeSeconds(time); this.TimeBytes = new byte[4]; Buffer.BlockCopy(serialized, startIndex, this.TimeBytes, 0, 4); this.PeerServices = (PeerServices)BitConverter.ToUInt64(serialized, startIndex + 4); this.PeerServicesBytes = new byte[8]; Buffer.BlockCopy(serialized, startIndex + 4, this.PeerServicesBytes, 0, 8); this.IPBytes = new byte[16]; Buffer.BlockCopy(serialized, startIndex + 12, this.IPBytes, 0, 16); this.IPAddress = new IPAddress(this.IPBytes); this.PortBytes = new byte[2]; Buffer.BlockCopy(serialized, startIndex + 28, this.PortBytes, 0, 2); var portBytes = new byte[2]; // swap to from network byte order portBytes[0] = this.PortBytes[1]; portBytes[1] = this.PortBytes[0]; this.Port = BitConverter.ToUInt16(portBytes, 0); } else { this.PeerServices = (PeerServices)BitConverter.ToUInt64(serialized, startIndex); this.PeerServicesBytes = new byte[8]; Buffer.BlockCopy(serialized, startIndex, this.PeerServicesBytes, 0, 8); this.IPBytes = new byte[16]; Buffer.BlockCopy(serialized, startIndex + 8, this.IPBytes, 0, 16); this.IPAddress = new IPAddress(this.IPBytes); this.PortBytes = new byte[2]; Buffer.BlockCopy(serialized, startIndex + 24, this.PortBytes, 0, 2); var portBytes = new byte[2]; // swap to from network byte order portBytes[0] = this.PortBytes[1]; portBytes[1] = this.PortBytes[0]; this.Port = BitConverter.ToUInt16(portBytes, 0); } }
public BitcoinVersionPayload(byte[] serialized) { this.ProtocolVersionBytes = new byte[4]; Buffer.BlockCopy(serialized, 0, this.ProtocolVersionBytes, 0, 4); this.ProtocolVersion = BitConverter.ToUInt32(this.ProtocolVersionBytes, 0); this.ServicesBytes = new byte[8]; Buffer.BlockCopy(serialized, 4, this.ServicesBytes, 0, 8); this.Services = (PeerServices)BitConverter.ToUInt64(this.ServicesBytes, 0); this.TimestampBytes = new byte[8]; Buffer.BlockCopy(serialized, 12, this.TimestampBytes, 0, 8); this.TimeStamp = DateTimeOffset.FromUnixTimeSeconds((long)BitConverter.ToUInt64(this.TimestampBytes, 0)); this.ReceiverAddressBytes = new byte[26]; Buffer.BlockCopy(serialized, 20, this.ReceiverAddressBytes, 0, 26); this.Receiver = new BitcoinNetworkAddressPayload(this.ReceiverAddressBytes, 0, false); this.SenderAddressBytes = new byte[26]; Buffer.BlockCopy(serialized, 46, this.SenderAddressBytes, 0, 26); this.Sender = new BitcoinNetworkAddressPayload(this.SenderAddressBytes, 0, false); this.NonceBytes = new byte[8]; Buffer.BlockCopy(serialized, 72, this.NonceBytes, 0, 8); this.UserAgent = new BitcoinVarString(serialized, 80); this.UserAgentBytes = this.UserAgent.VarStringBytes; this.StartHeightBytes = new byte[4]; Buffer.BlockCopy(serialized, 80 + this.UserAgent.SerializedLength, this.StartHeightBytes, 0, 4); this.StartHeight = BitConverter.ToUInt32(this.StartHeightBytes, 0); this.RelayBytes = new byte[1]; this.RelayBytes[0] = serialized[80 + this.UserAgent.SerializedLength + 4]; }
public async void ReceiveMessageRelayRecordAsync(IPAddress ipAddress, int port, PeerServices peerServices, string userAgent) { try { if (peerServices.HasFlag(PeerServices.MessageRelay)) { var messageRelayRecord = new MessageRelayRecord { Id = PeerSerializer.CreatePeerId(ipAddress, DefaultMessagingPort), // pretend we have had a successful connection already (it is likely, since we have just had a version handshake via the protocol port LastSeenUtc = DateTime.UtcNow, LastErrorUtc = default,