diff options
author | Determinant <[email protected]> | 2019-06-11 14:25:40 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-06-11 14:25:40 -0400 |
commit | ef377f5d85503451a16d50fbc535a7537a28b57f (patch) | |
tree | a57d9268a0984107ad7b483c942a992df6e6a6ec | |
parent | 05ffb2ce9f4a0cbaca05a1d46b040743d661ce25 (diff) |
...
-rw-r--r-- | include/salticidae/netaddr.h | 4 | ||||
-rw-r--r-- | include/salticidae/network.h | 14 | ||||
-rw-r--r-- | include/salticidae/stream.h | 5 | ||||
-rw-r--r-- | src/netaddr.cpp | 10 | ||||
-rw-r--r-- | src/network.cpp | 4 | ||||
-rw-r--r-- | src/stream.cpp | 9 |
6 files changed, 26 insertions, 20 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); diff --git a/src/netaddr.cpp b/src/netaddr.cpp index 109a6ac..1387b84 100644 --- a/src/netaddr.cpp +++ b/src/netaddr.cpp @@ -30,6 +30,16 @@ uint32_t netaddr_get_ip(const netaddr_t *self) { return self->ip; } uint16_t netaddr_get_port(const netaddr_t *self) { return self->port; } +netaddr_array_t *netaddr_array_new() { return new netaddr_array_t(); } +netaddr_array_t *netaddr_array_new_from_addrs(const netaddr_t * const *addrs, size_t naddrs) { + auto res = new netaddr_array_t(); + for (size_t i = 0; i < naddrs; i++) + (*res)[i] = *addrs[i]; + return res; +} + +void netaddr_array_free(netaddr_array_t *self) { delete self; } + } #endif diff --git a/src/network.cpp b/src/network.cpp index 673cc24..39eec4c 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -111,8 +111,8 @@ void peernetwork_send_msg(peernetwork_t *self, void peernetwork_multicast_msg(peernetwork_t *self, msg_t *_moved_msg, - const netaddr_t *paddrs, size_t npaddrs) { - self->_multicast_msg(std::move(*_moved_msg), paddrs, npaddrs); + const netaddr_array_t *paddrs) { + self->multicast_msg(std::move(*_moved_msg), *paddrs); delete _moved_msg; } diff --git a/src/stream.cpp b/src/stream.cpp index 3e24292..b14bd6a 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -24,8 +24,8 @@ void uint256_unserialize(uint256_t *self, datastream_t *s) { } datastream_t *datastream_new() { return new datastream_t(); } -datastream_t *datastream_new_from_bytes(const uint8_t *begin, const uint8_t *end) { - return new datastream_t(begin, end); +datastream_t *datastream_new_from_bytes(const uint8_t *base, size_t size) { + return new datastream_t(base, base + size); } void datastream_free(const datastream_t *self) { delete self; } @@ -54,9 +54,8 @@ void datastream_put_i16(datastream_t *self, int16_t val) { *self << val; } void datastream_put_i32(datastream_t *self, int32_t val) { *self << val; } void datastream_put_i64(datastream_t *self, int64_t val) { *self << val; } -void datastream_put_data(datastream_t *self, - const uint8_t *begin, const uint8_t *end) { - self->put_data(begin, end); +void datastream_put_data(datastream_t *self, const uint8_t *base, size_t size) { + self->put_data(base, base + size); } uint8_t datastream_get_u8(datastream_t *self) { uint8_t val; *self >> val; return val; } |