public Task <Message> PutConfirmAsync(PeerAddress remotePeer, PutBuilder putBuilder, ChannelCreator channelCreator) { Utils.NullCheck(remotePeer); DataMap dataMap; if (putBuilder.DataMap != null) { dataMap = new DataMap(putBuilder.DataMap); } else { dataMap = new DataMap(putBuilder.LocationKey, putBuilder.DomainKey, putBuilder.VersionKey, putBuilder.DataMapConvert); } var message = CreateRequestMessage(remotePeer, Rpc.Commands.PutConfirm.GetNr(), Message.MessageType.Request1); if (putBuilder.IsSign) { message.SetPublicKeyAndSign(putBuilder.KeyPair); } message.SetDataMap(dataMap); var tcsResponse = new TaskCompletionSource <Message>(message); var requestHandler = new RequestHandler(tcsResponse, PeerBean, ConnectionBean, putBuilder); if (!putBuilder.IsForceUdp) { return(requestHandler.SendTcpAsync(channelCreator)); } return(requestHandler.SendUdpAsync(channelCreator)); }
public Task <Message> PutMetaAsync(PeerAddress remotePeer, PutBuilder putBuilder, ChannelCreator channelCreator) { Utils.NullCheck(remotePeer); DataMap dataMap; if (putBuilder.DataMap != null) { dataMap = new DataMap(putBuilder.DataMap); } else { dataMap = new DataMap(putBuilder.LocationKey, putBuilder.DomainKey, putBuilder.VersionKey, putBuilder.DataMapConvert); } var type = putBuilder.ChangePublicKey != null ? Message.MessageType.Request2 : Message.MessageType.Request1; var message = CreateRequestMessage(remotePeer, Rpc.Commands.PutMeta.GetNr(), type); if (putBuilder.IsSign) { message.SetPublicKeyAndSign(putBuilder.KeyPair); } else if (type == Message.MessageType.Request2) { throw new MemberAccessException("Can only change public key if message is signed."); } if (putBuilder.ChangePublicKey != null) { message.SetKey(putBuilder.LocationKey); message.SetKey(putBuilder.DomainKey); message.SetPublicKey(putBuilder.ChangePublicKey); } else { message.SetDataMap(dataMap); } var tcsResponse = new TaskCompletionSource <Message>(message); var requestHandler = new RequestHandler(tcsResponse, PeerBean, ConnectionBean, putBuilder); if (!putBuilder.IsForceUdp) { return(requestHandler.SendTcpAsync(channelCreator)); } return(requestHandler.SendUdpAsync(channelCreator)); }
public Task <Message> PutReplica(PeerAddress remotePeer, PutBuilder putBuilder, ChannelCreator channelCreator) { return(PutAsync(remotePeer, putBuilder, Message.MessageType.Request1, Rpc.Commands.ReplicaPut, channelCreator)); }
/// <summary> /// Stores data on a remote peer. Only stores data if the data does not already exist. /// </summary> /// <param name="remotePeer">The remote peer on which to store the data.</param> /// <param name="putBuilder">The builder to use for this operation.</param> /// <param name="channelCreator">The channel creator that will be used.</param> /// <returns>The future response message.</returns> public Task <Message> PutIfAbsent(PeerAddress remotePeer, PutBuilder putBuilder, ChannelCreator channelCreator) { var type = putBuilder.IsProtectDomain ? Message.MessageType.Request4 : Message.MessageType.Request3; return(PutAsync(remotePeer, putBuilder, type, Rpc.Commands.Put, channelCreator)); }