Пример #1
0
        private bool PostSynHostEntryMessage(IMalockSocket socket, string key, string identity, HostEntry entry)
        {
            if (entry == null || string.IsNullOrEmpty(identity) || string.IsNullOrEmpty(key))
            {
                return(false);
            }
            MalockNnsMessage message = new MalockNnsMessage();

            message.Key      = key;
            message.Identity = identity;
            message.Sequence = MalockMessage.NewId();
            message.Command  = MalockNnsMessage.SERVER_NNS_COMMAND_SYN_HOSTENTRYINFO;
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    message.Serialize(bw);
                    if (entry != null)
                    {
                        entry.Serialize(bw);
                    }
                    MalockMessage.TrySendMessage(socket, stream);
                }
            }
            return(true);
        }
Пример #2
0
        private void QueryHostEntry(MalockSocket socket, int sequence, string key)
        {
            string           identity;
            HostEntry        entry   = this.nnsTable.GetEntry(key, out identity);
            MalockNnsMessage message = new MalockNnsMessage();

            message.Key      = key;
            message.Sequence = sequence;
            message.Command  = MalockMessage.COMMON_COMMAND_ERROR;
            if (entry != null)
            {
                message.Command = MalockNnsMessage.CLIENT_COMMAND_QUERYHOSTENTRYINFO;
            }
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    message.Serialize(bw);
                    if (entry != null)
                    {
                        entry.Serialize(bw);
                    }
                    MalockMessage.TrySendMessage(socket, stream);
                }
            }
            this.PostSynHostEntryMessage(this.nnsStanbyClient, key, identity, entry);
        }
Пример #3
0
        protected override void OnConnected(object sender, EventArgs e)
        {
            MalockNnsMessage message = new MalockNnsMessage();

            message.Command  = MalockNnsMessage.SERVER_NNS_COMMAND_DUMPHOSTENTRYINFO;
            message.Sequence = MalockMessage.NewId();
            MalockMessage.TrySendMessage(this, message);
        }
Пример #4
0
 private void ProcessClient(MalockSocket socket, MalockNnsMessage message)
 {
     if (message.Command == MalockNnsMessage.CLIENT_COMMAND_QUERYHOSTENTRYINFO)
     {
         this.QueryHostEntry(socket, message.Sequence, message.Key);
     }
     else if (message.Command == MalockNnsMessage.CLIENT_COMMAND_DUMPHOSTENTRYINFO)
     {
         this.DumpHostEntry(socket, message);
     }
 }
Пример #5
0
        private void ProcessReceived(object sender, MalockSocketStream e)
        {
            MalockNnsMessage message = null;

            using (Stream stream = e.Stream)
            {
                MalockNnsMessage.TryDeserialize(stream, out message);
                if (message != null)
                {
                    this.ProcessMessage(e.Socket, message, stream);
                }
            }
        }
Пример #6
0
 private void ProcessServer(MalockSocket socket, MalockNnsMessage message, Stream stream)
 {
     if (message.Command == MalockNnsMessage.SERVER_NNS_COMMAND_SYN_HOSTENTRYINFO)
     {
         this.SynQueryHostEntry(socket, message.Identity, message.Key, HostEntry.Deserialize(stream));
     }
     else if (message.Command == MalockNnsMessage.SERVER_NDN_COMMAND_REGISTERHOSTENTRYINFO)
     {
         this.RegisterHostEntry(socket, message.Sequence, HostEntry.Deserialize(stream));
     }
     else if (message.Command == MalockNnsMessage.SERVER_NNS_COMMAND_DUMPHOSTENTRYINFO)
     {
         this.DumpHostEntry(socket, message);
     }
 }
Пример #7
0
        protected override void OnReceived(object sender, MalockSocketStream e)
        {
            MalockNnsMessage message = null;

            using (Stream stream = e.Stream)
            {
                if (!MalockNnsMessage.TryDeserialize(e.Stream, out message))
                {
                    this.Abort();
                    return;
                }
                if (message.Command == MalockNnsMessage.SERVER_NNS_COMMAND_DUMPHOSTENTRYINFO)
                {
                    this.DumpHostEntry(stream);
                }
            }
        }
Пример #8
0
        private void ProcessMessage(MalockSocket socket, MalockNnsMessage message, Stream stream)
        {
            switch (socket.LinkMode)
            {
            case MalockMessage.LINK_MODE_CLIENT:
                this.ProcessClient(socket, message);
                break;

            case MalockMessage.LINK_MODE_SERVER:
                this.ProcessServer(socket, message, stream);
                break;

            default:
                socket.Abort();
                break;
            }
        }
Пример #9
0
        private void RegisterHostEntry(MalockSocket socket, int sequence, HostEntry entry)
        {
            MalockNnsMessage message = new MalockNnsMessage();

            message.Sequence = sequence;
            message.Command  = MalockMessage.COMMON_COMMAND_ERROR;
            if (entry != null)
            {
                lock (this.nnsTable.GetSynchronizationObject())
                {
                    if (this.nnsTable.Register(socket.Identity, entry))
                    {
                        message.Command = MalockNnsMessage.SERVER_NDN_COMMAND_REGISTERHOSTENTRYINFO;
                    }
                    this.nnsTable.SetAvailable(socket.Identity, socket.Address, true);
                }
            }
            MalockMessage.TrySendMessage(socket, message);
        }
Пример #10
0
        private void DumpHostEntry(MalockSocket socket, MalockNnsMessage message)
        {
            MalockNnsMessage msg = new MalockNnsMessage();

            msg.Sequence = message.Sequence;
            msg.Command  = message.Command;
            do
            {
                var hosts = this.nnsTable.GetAllHosts();
                lock (this.nnsTable)
                {
                    NnsTable.Host.SerializeAll(hosts, (count, stream) =>
                    {
                        using (MemoryStream ms = (MemoryStream)stream)
                        {
                            MalockMessage.TrySendMessage(socket, message, ms.GetBuffer(), 0, unchecked ((int)ms.Position));
                        }
                    });
                }
            } while (false);
        }