Exemplo n.º 1
0
func (pr *Peer) handleKVStoreDelete(packet *packets.KVStorePacket, request *packets.Packet) {
	pr.Logger.Debug("Peer", "%02X: KVStoreDelete: %s", pr.ServerNetworkNode.ID, packet.Key)
	found := pr.Server.KVStore.Delete(packet.Key)

	var response *packets.Packet

	if found {
		response = packets.NewResponsePacket(packets.CMD_KVSTORE_ACK, request.ID, packet.Key)
		pr.Logger.Debug("Peer", "%02X: KVStoreDelete: %s Deleted, replying", pr.ServerNetworkNode.ID, packet.Key)
	} else {
		response = packets.NewResponsePacket(packets.CMD_KVSTORE_NOT_FOUND, request.ID, packet.Key)
		pr.Logger.Debug("Peer", "%02X: KVStoreDelete: %s Not found, replying", pr.ServerNetworkNode.ID, packet.Key)
	}

	pr.SendPacket(response)
}
Exemplo n.º 2
0
func (pr *Peer) handleKVStoreSet(packet *packets.KVStorePacket, request *packets.Packet) {
	pr.Logger.Debug("Peer", "%02X: KVStoreSet: %s = %s", pr.ServerNetworkNode.ID, packet.Key, packet.Data)
	pr.Server.KVStore.Set(
		packet.Key,
		packet.Data,
		packet.Flags,
		packet.ExpiresAt)

	response := packets.NewResponsePacket(packets.CMD_KVSTORE_ACK, request.ID, packet.Key)
	pr.Logger.Debug("Peer", "%02X: KVStoreSet: %s Acknowledge, replying", pr.ServerNetworkNode.ID, packet.Key)
	pr.SendPacket(response)
}
Exemplo n.º 3
0
func (pr *Peer) handleKVStoreGet(packet *packets.KVStorePacket, request *packets.Packet) {
	pr.Logger.Debug("Peer", "%02X: KVStoreGet: %s", pr.ServerNetworkNode.ID, packet.Key)
	value, flags, found := pr.Server.KVStore.Get(packet.Key)

	var response *packets.Packet

	if found {
		payload := packets.KVStorePacket{
			Command: packets.CMD_KVSTORE_GET,
			Key:     packet.Key,
			Data:    value,
			Flags:   flags,
		}
		response = packets.NewResponsePacket(packets.CMD_KVSTORE_ACK, request.ID, payload)
		pr.Logger.Debug("Peer", "%02X: KVStoreGet: %s = %s, replying", pr.ServerNetworkNode.ID, packet.Key, value)
	} else {
		response = packets.NewResponsePacket(packets.CMD_KVSTORE_NOT_FOUND, request.ID, packet.Key)
		pr.Logger.Debug("Peer", "%02X: KVStoreGet: %s Not found, replying", pr.ServerNetworkNode.ID, packet.Key)
	}

	pr.SendPacket(response)
}