Пример #1
0
        public void HandlePeerAnnounce(CourierAnnounceV1 announce, IPAddress remoteAddress)
        {
            if (revisionCounter.TryAdvance(announce.PropertiesRevision))
            {
                lock (updateSynchronization) {
                    if (revisionCounter.IsCurrentCount(announce.PropertiesRevision))
                    {
                        using (var ms = new MemoryStream(announce.PropertiesData, announce.PropertiesDataOffset, announce.PropertiesDataLength))
                            using (var reader = new BinaryReader(ms)) {
                                var newProperties = (System.Collections.Generic.IReadOnlyDictionary <Guid, byte[]>)pofSerializer.Deserialize(reader);
                                var previousKeys  = new HashSet <Guid>(properties.Keys);
                                var nextKeys      = new HashSet <Guid>(newProperties.Keys);
                                var keptKeys      = new HashSet <Guid>(previousKeys).With(s => s.IntersectWith(nextKeys));
                                var addedKeys     = new HashSet <Guid>(nextKeys).With(s => s.ExceptWith(previousKeys));
                                var removedKeys   = new HashSet <Guid>(previousKeys).With(s => s.ExceptWith(nextKeys));

                                keptKeys.ForEach(k => properties[k] = newProperties[k]);
                                addedKeys.ForEach(k => properties.Add(k, newProperties[k]));
                                removedKeys.ForEach(k => properties.Remove(k));

                                this.lastAddress = remoteAddress;

                                Console.WriteLine("HPA of " + remoteAddress + " (" + identifier.ToString("N").Substring(0, 8) + ") WITH " + newProperties);
                            }
                    }
                }
            }
        }
Пример #2
0
 public void HandlePeerAnnounce(Guid senderId, CourierAnnounceV1 announce, IPEndPoint remoteEndPoint)
 {
     peerContextsById.AddOrUpdate(
         senderId,
         id => new RemoteCourierEndpointImpl(id, announce.Name, new RevisionCounterImpl(), courierSerializer, remoteEndPoint.Address).With(x => x.HandlePeerAnnounce(announce, remoteEndPoint.Address)),
         (id, context) => context.With(x => x.HandlePeerAnnounce(announce, remoteEndPoint.Address))
         );
 }
 public CourierAnnounceV1Tests()
 {
     testObj = new CourierAnnounceV1(name, propertiesRevision, propertiesData, 0, propertiesData.Length);
 }
 private void HandleInboundAnnounce(Guid senderId, CourierAnnounceV1 payload, IPEndPoint remoteEndPoint)
 {
     peerRegistry.HandlePeerAnnounce(senderId, payload, remoteEndPoint);
 }