private void ProcessReceived(MemoryStream stream) { using (stream) { if (stream.Position >= stream.Length) { return; } bool debarkation = false; do { bool localTaken = false; this.connectwait.Enter(ref localTaken); if (localTaken) { debarkation = this.connected; if (!debarkation) { this.connected = true; } this.connectwait.Exit(); } } while (false); if (!debarkation) { using (BinaryReader br = new BinaryReader(stream)) { IPEndPoint ipep = this.remoteep as IPEndPoint; if (ipep != null) { this.LinkMode = br.ReadByte(); int port = br.ReadUInt16(); this.identity = MalockMessage.FromStringInReadStream(br); this.remoteport = ipep.Port; this.address = Ipep.ToIpepString(ipep.Address.ToString(), port); } } if (string.IsNullOrEmpty(this.identity)) { this.Abort(); } else { this.OnConnected(EventArgs.Empty); } } else if (string.IsNullOrEmpty(this.identity)) { this.Abort(); } else { this.OnReceived(new MalockSocketStream(this, stream)); } } }
public static EndPoint ToEndPoint(NSJSValue value) { string ep = (value as NSJSString)?.Value; if (string.IsNullOrEmpty(ep)) { return(null); } try { return(Ipep.ToIpep(ep)); } catch { return(null); } }
private bool TryRegisterHostEntryMessage(IMalockSocket malock) { if (malock == null) { return(false); } MSG msg = new MSG(); msg.Command = MSG.SERVER_NDN_COMMAND_REGISTERHOSTENTRYINFO; msg.Sequence = MSG.NewId(); using (MemoryStream ms = new MemoryStream()) { msg.Serialize(ms); do { HostEntry entry = new HostEntry(); entry.Primary.Address = Ipep.ToIpepString(GetEtherAddress(malock), this.configuration.Port); entry.Standby.Address = configuration.StandbyNode; entry.Serialize(ms); } while (false); return(MSG.TrySendMessage(malock, ms)); } }
internal MalockSocket(string identity, string address, int listenport, int linkMode) : this(identity, Ipep.ToIpep(address), listenport, linkMode) { }