Пример #1
0
        private bool IdentifyPeer(Pipe pipe)
        {
            Blob identity;

            Msg msg = pipe.Read ();
            if (msg == null)
                return false;

            if (msg.Size == 0) {
                //  Fall back on the auto-generation
                byte[] buf = new byte[5];

                buf[0] = 0;

                byte[] result = BitConverter.GetBytes(m_nextPeerId++);
                //if (BitConverter.IsLittleEndian)
                //{
                //    Array.Reverse(result);
                //}

                Buffer.BlockCopy(result, 0, buf, 1, 4);
                identity = new Blob(buf);
            }
            else {
                identity = new Blob(msg.Data);

                //  Ignore peers with duplicate ID.
                if (m_outpipes.ContainsKey(identity))
                    return false;
            }

            pipe.Identity = identity;
            //  Add the record into output pipes lookup table
            Outpipe outpipe = new Outpipe(pipe, true);
            m_outpipes.Add (identity, outpipe);

            return true;
        }
Пример #2
0
        protected override void XReadActivated(Pipe pipe)
        {
            //  There are some subscriptions waiting. Let's process them.
            Msg sub;
            while ((sub = pipe.Read()) != null) {

                //  Apply the subscription to the trie.
                byte[] data = sub.Data;
                int size = sub.Size;
                if (size > 0 && (data[0] == 0 || data[0] == 1)) {
                    bool unique;
                    if (data[0] == 0)
                        unique = m_subscriptions.Remove (data , 1, pipe);
                    else
                        unique = m_subscriptions.Add (data , 1, pipe);

                    //  If the subscription is not a duplicate, store it so that it can be
                    //  passed to used on next recv call.
                    if (m_options.SocketType == ZmqSocketType.Xpub && (unique || m_verbose))
                        m_pending.AddToBack(new Blob (sub.Data));
                }
            }
        }