public static byte[] Serialize(MessageRelayRecord messageRelayRecord) { byte[] serialized = PocoSerializer.Begin() .Append(messageRelayRecord.Id) .Append(messageRelayRecord.LastSeenUtc) .Append(messageRelayRecord.LastErrorUtc) .Append(messageRelayRecord.ErrorScore) .Finish(); return(serialized); }
public async Task UpdatePeerAfterHandshake(MessageRelayRecord messageRelayRecord) { await SemaphoreSlim.WaitAsync(); try { //Peer existingPeer = await this.messageNodeRecords.Get(peer.Id); //existingPeer.PeerServices = peer.PeerServices; //existingPeer.LastSeen = peer.LastSeen; //existingPeer.LastError = DateTime.MaxValue; //await this.messageNodeRecords.Update(existingPeer, null); } finally { SemaphoreSlim.Release(); } }
public async Task AddMessageNodeRecordAsync(MessageRelayRecord peer) { await SemaphoreSlim.WaitAsync(); try { var existing = await this.messageNodeRecords.Get(peer.Id); if (existing == null) { await this.messageNodeRecords.Add(peer); } } finally { SemaphoreSlim.Release(); } }
public static MessageRelayRecord Deserialize(byte[] serializedMessageNodeRecord) { if (serializedMessageNodeRecord == null) { return(null); } var ser = PocoSerializer.GetDeserializer(serializedMessageNodeRecord); var messageNodeRecord = new MessageRelayRecord { Id = ser.MakeString(0), LastSeenUtc = ser.MakeDateTime(1), LastErrorUtc = ser.MakeDateTime(2), ErrorScore = ser.MakeInt32(3) }; var(ipAddress, port) = messageNodeRecord.Id.ToAddress(); messageNodeRecord.IpAddress = ipAddress; messageNodeRecord.MessagingPort = port; return(messageNodeRecord); }