diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/salticidae/netaddr.h | 4 | ||||
-rw-r--r-- | include/salticidae/network.h | 14 | ||||
-rw-r--r-- | include/salticidae/stream.h | 5 |
3 files changed, 10 insertions, 13 deletions
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<netaddr_t>; #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<OpcodeType> { template<typename MsgType> void multicast_msg(MsgType &&msg, const std::vector<NetAddr> &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<O, _, __>::_send_msg(Msg &&msg, const NetAddr &paddr) { template<typename O, O _, O __> template<typename MsgType> void PeerNetwork<O, _, __>::multicast_msg(MsgType &&msg, const std::vector<NetAddr> &paddrs) { - return _multicast_msg(MsgType(msg), &paddrs[0], paddrs.size()); -} - -template<typename O, O _, O __> -void PeerNetwork<O, _, __>::_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); |