From ef377f5d85503451a16d50fbc535a7537a28b57f Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 11 Jun 2019 14:25:40 -0400 Subject: ... --- include/salticidae/netaddr.h | 4 ++++ include/salticidae/network.h | 14 ++++---------- include/salticidae/stream.h | 5 ++--- 3 files changed, 10 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/salticidae/netaddr.h b/include/salticidae/netaddr.h index 01510e0..909e092 100644 --- a/include/salticidae/netaddr.h +++ b/include/salticidae/netaddr.h @@ -125,8 +125,10 @@ namespace std { } using netaddr_t = salticidae::NetAddr; +using netaddr_array_t = std::vector; #else typedef struct netaddr_t netaddr_t; +typedef struct netaddr_array_t netaddr_array_t; #endif #ifdef SALTICIDAE_CBINDINGS @@ -143,6 +145,8 @@ bool netaddr_is_eq(const netaddr_t *a, const netaddr_t *b); bool netaddr_is_null(const netaddr_t *self); uint32_t netaddr_get_ip(const netaddr_t *self); uint16_t netaddr_get_port(const netaddr_t *self); +netaddr_array_t *netaddr_array_new(); +netaddr_array_t *netaddr_array_new_from_addrs(const netaddr_t * const *paddrs, size_t naddrs); #ifdef __cplusplus } diff --git a/include/salticidae/network.h b/include/salticidae/network.h index 32d638a..4c5b6d0 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -437,7 +437,6 @@ class PeerNetwork: public MsgNetwork { template void multicast_msg(MsgType &&msg, const std::vector &paddrs); - inline void _multicast_msg(Msg &&msg, const NetAddr *paddrs, size_t npaddrs); void listen(NetAddr listen_addr); conn_t connect(const NetAddr &addr) = delete; @@ -738,16 +737,11 @@ void PeerNetwork::_send_msg(Msg &&msg, const NetAddr &paddr) { template template void PeerNetwork::multicast_msg(MsgType &&msg, const std::vector &paddrs) { - return _multicast_msg(MsgType(msg), &paddrs[0], paddrs.size()); -} - -template -void PeerNetwork::_multicast_msg(Msg &&msg, const NetAddr *paddrs, size_t npaddrs) { this->disp_tcall->async_call( - [this, msg=std::move(msg), paddrs, npaddrs](ThreadCall::Handle &) { - for (size_t i = 0; i < npaddrs; i++) + [this, msg=std::move(msg), paddrs](ThreadCall::Handle &) { + for (auto &addr: paddrs) { - auto it = id2peer.find(paddrs[i]); + auto it = id2peer.find(addr); if (it == id2peer.end()) throw PeerNetworkError("peer does not exist"); send_msg(std::move(msg), it->second->conn); @@ -865,7 +859,7 @@ const peernetwork_conn_t *peernetwork_get_peer_conn(const peernetwork_t *self, c msgnetwork_t *peernetwork_as_msgnetwork(peernetwork_t *self); msgnetwork_conn_t *msgnetwork_conn_new_from_peernetwork_conn(const peernetwork_conn_t *conn); void peernetwork_send_msg(peernetwork_t *self, msg_t * _moved_msg, const netaddr_t *paddr); -void peernetwork_multicast_msg(peernetwork_t *self, msg_t *_moved_msg, const netaddr_t *paddrs, size_t npaddrs); +void peernetwork_multicast_msg(peernetwork_t *self, msg_t *_moved_msg, const netaddr_array_t *paddrs); void peernetwork_listen(peernetwork_t *self, const netaddr_t *listen_addr); #ifdef __cplusplus diff --git a/include/salticidae/stream.h b/include/salticidae/stream.h index 843fba6..cf007ac 100644 --- a/include/salticidae/stream.h +++ b/include/salticidae/stream.h @@ -502,7 +502,7 @@ void uint256_serialize(const uint256_t *self, datastream_t *s); void uint256_unserialize(uint256_t *self, datastream_t *s); datastream_t *datastream_new(); -datastream_t *datastream_new_from_bytes(const uint8_t *begin, const uint8_t *end); +datastream_t *datastream_new_from_bytes(const uint8_t *base, size_t size); void datastream_free(const datastream_t *self); void datastream_assign_by_copy(datastream_t *dst, const datastream_t *src); @@ -520,8 +520,7 @@ void datastream_put_i8(datastream_t *self, int8_t val); void datastream_put_i16(datastream_t *self, int16_t val); void datastream_put_i32(datastream_t *self, int32_t val); void datastream_put_i64(datastream_t *self, int64_t val); -void datastream_put_data(datastream_t *self, - const uint8_t *begin, const uint8_t *end); +void datastream_put_data(datastream_t *self, const uint8_t *base, size_t size); uint8_t datastream_get_u8(datastream_t *self); uint16_t datastream_get_u16(datastream_t *self); -- cgit v1.2.3-70-g09d2