/** * Send an UDP unicast datagram to the given peer. * @return 'false' if the datagram can't be sent. */ INetworkListener::SendStatus UDPListener::send(Common::MessageHeader::MessageType type, const google::protobuf::Message& message, const Common::Hash& peerID) { PM::IPeer* peer = this->peerManager->getPeer(peerID); if (!peer) return INetworkListener::PEER_UNKNOWN; int messageSize; if (!(messageSize = this->writeMessageToBuffer(type, message))) return INetworkListener::MESSAGE_TOO_LARGE; L_DEBU(QString("Send unicast UDP to %1, header.getType(): %2, message size: %3 \n%4"). arg(peer->toStringLog()). arg(Common::MessageHeader::messToStr(type)). arg(messageSize). arg(Common::ProtoHelper::getDebugStr(message)) ); if (this->unicastSocket.writeDatagram(this->buffer, messageSize, peer->getIP(), peer->getPort()) == -1) { L_WARN(QString("Unable to send datagram (unicast): error: %1").arg(this->unicastSocket.errorString())); return INetworkListener::UNABLE_TO_SEND; } return INetworkListener::OK; }
void UDPListener::send(Common::MessageHeader::MessageType type, const Common::Hash& peerID, const google::protobuf::Message& message) { PM::IPeer* peer = this->peerManager->getPeer(peerID); if (!peer) { L_WARN(QString("Unable to find the peer %1").arg(peerID.toStr())); return; } int messageSize; if (!(messageSize = this->writeMessageToBuffer(type, message))) return; L_DEBU(QString("Send unicast UDP to %1 : header.getType() = %2, message size = %3 \n%4"). arg(peer->toStringLog()). arg(Common::MessageHeader::messToStr(type)). arg(messageSize). arg(Common::ProtoHelper::getDebugStr(message)) ); if (this->unicastSocket.writeDatagram(this->buffer, messageSize, peer->getIP(), peer->getPort()) == -1) L_WARN("Unable to send datagram"); }