示例#1
0
 public NeighborsMessage(byte[] data)
     : base(UdpMessageType.DISCOVER_NEIGHBORS, data)
 {
     try
     {
         this.message = Protocol.Neighbours.Parser.ParseFrom(data);
     }
     catch (System.Exception e)
     {
         Logger.Error(e.Message);
     }
 }
示例#2
0
        public NeighborsMessage(Node from, List <Node> neighbours, long sequence)
            : base(UdpMessageType.DISCOVER_NEIGHBORS, null)
        {
            this.message           = new Protocol.Neighbours();
            this.message.Timestamp = sequence;

            neighbours.ForEach(neighbour =>
            {
                Protocol.Endpoint endpoint = new Protocol.Endpoint();
                endpoint.NodeId            = ByteString.CopyFrom(neighbour.Id);
                endpoint.Port    = neighbour.Port;
                endpoint.Address = ByteString.CopyFrom(Encoding.UTF8.GetBytes(neighbour.Host));

                this.message.Neighbours_.Add(endpoint);
            });

            this.message.From         = new Protocol.Endpoint();
            this.message.From.NodeId  = ByteString.CopyFrom(from.Id);
            this.message.From.Port    = from.Port;
            this.message.From.Address = ByteString.CopyFrom(Encoding.UTF8.GetBytes(from.Host));
            this.data = this.message.ToByteArray();
        }