aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-28 15:37:22 -0400
committerDeterminant <[email protected]>2019-06-28 15:37:22 -0400
commit710e9e8961cf5039b425e66d2042942b7e4af0c8 (patch)
treef69db46552945e945b5603d1d254df7e77d17b26 /src
parentd28bf1b0c8baec3c5ab40cfb988ff974f98da439 (diff)
clean up code
Diffstat (limited to 'src')
-rw-r--r--src/netaddr.cpp17
-rw-r--r--src/network.cpp28
-rw-r--r--src/stream.cpp16
3 files changed, 46 insertions, 15 deletions
diff --git a/src/netaddr.cpp b/src/netaddr.cpp
index cb8a3d2..736d606 100644
--- a/src/netaddr.cpp
+++ b/src/netaddr.cpp
@@ -2,22 +2,33 @@
#ifdef SALTICIDAE_CBINDINGS
#include "salticidae/netaddr.h"
+using namespace salticidae;
+
extern "C" {
netaddr_t *netaddr_new() { return new netaddr_t(); }
void netaddr_free(const netaddr_t *self) { delete self; }
-netaddr_t *netaddr_new_from_ip_port(uint32_t ip, uint16_t port) {
+netaddr_t *netaddr_new_from_ip_port(uint32_t ip, uint16_t port, SalticidaeCError *cerror) {
+ SALTICIDAE_CERROR_TRY(cerror)
return new netaddr_t(ip, port);
+ SALTICIDAE_CERROR_CATCH(cerror)
+ return nullptr;
}
-netaddr_t *netaddr_new_from_sip_port(const char *ip, uint16_t port) {
+netaddr_t *netaddr_new_from_sip_port(const char *ip, uint16_t port, SalticidaeCError *cerror) {
+ SALTICIDAE_CERROR_TRY(cerror)
return new netaddr_t(ip, port);
+ SALTICIDAE_CERROR_CATCH(cerror)
+ return nullptr;
}
-netaddr_t *netaddr_new_from_sipport(const char *ip_port_addr) {
+netaddr_t *netaddr_new_from_sipport(const char *ip_port_addr, SalticidaeCError *cerror) {
+ SALTICIDAE_CERROR_TRY(cerror)
return new netaddr_t(ip_port_addr);
+ SALTICIDAE_CERROR_CATCH(cerror)
+ return nullptr;
}
netaddr_t *netaddr_copy(const netaddr_t *self) {
diff --git a/src/network.cpp b/src/network.cpp
index a02ead1..2dc7d1f 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -190,19 +190,23 @@ peernetwork_t *peernetwork_new(const eventcontext_t *ec, const peernetwork_confi
void peernetwork_free(const peernetwork_t *self) { delete self; }
-void peernetwork_add_peer(peernetwork_t *self, const netaddr_t *paddr) {
- self->add_peer(*paddr);
+void peernetwork_add_peer(peernetwork_t *self, const netaddr_t *addr) {
+ self->add_peer(*addr);
}
-bool peernetwork_has_peer(const peernetwork_t *self, const netaddr_t *paddr) {
- return self->has_peer(*paddr);
+void peernetwork_del_peer(peernetwork_t *self, const netaddr_t *addr) {
+ self->del_peer(*addr);
+}
+
+bool peernetwork_has_peer(const peernetwork_t *self, const netaddr_t *addr) {
+ return self->has_peer(*addr);
}
const peernetwork_conn_t *peernetwork_get_peer_conn(const peernetwork_t *self,
- const netaddr_t *paddr,
+ const netaddr_t *addr,
SalticidaeCError *cerror) {
SALTICIDAE_CERROR_TRY(cerror)
- return new peernetwork_conn_t(self->get_peer_conn(*paddr));
+ return new peernetwork_conn_t(self->get_peer_conn(*addr));
SALTICIDAE_CERROR_CATCH(cerror)
return nullptr;
}
@@ -227,18 +231,18 @@ peernetwork_conn_t *peernetwork_conn_copy(const peernetwork_conn_t *self) {
void peernetwork_conn_free(const peernetwork_conn_t *self) { delete self; }
-void peernetwork_send_msg(peernetwork_t *self, const msg_t * msg, const netaddr_t *paddr) {
- self->_send_msg(*msg, *paddr);
+void peernetwork_send_msg(peernetwork_t *self, const msg_t * msg, const netaddr_t *addr) {
+ self->_send_msg(*msg, *addr);
}
void peernetwork_send_msg_deferred_by_move(peernetwork_t *self,
- msg_t *_moved_msg, const netaddr_t *paddr) {
- self->_send_msg_deferred(std::move(*_moved_msg), *paddr);
+ msg_t *_moved_msg, const netaddr_t *addr) {
+ self->_send_msg_deferred(std::move(*_moved_msg), *addr);
}
void peernetwork_multicast_msg_by_move(peernetwork_t *self,
- msg_t *_moved_msg, const netaddr_array_t *paddrs) {
- self->_multicast_msg(std::move(*_moved_msg), *paddrs);
+ msg_t *_moved_msg, const netaddr_array_t *addrs) {
+ self->_multicast_msg(std::move(*_moved_msg), *addrs);
}
void peernetwork_listen(peernetwork_t *self, const netaddr_t *listen_addr, SalticidaeCError *cerror) {
diff --git a/src/stream.cpp b/src/stream.cpp
index f5d4ac9..6b208aa 100644
--- a/src/stream.cpp
+++ b/src/stream.cpp
@@ -133,6 +133,14 @@ bytearray_t *bytearray_new_moved_from_datastream(datastream_t *_moved_src) {
}
}
+bytearray_t *bytearray_new_copied_from_datastream(datastream_t *src) {
+ try {
+ return new bytearray_t(*src);
+ } catch (...) {
+ return nullptr;
+ }
+}
+
bytearray_t *bytearray_new_from_hex(const char *hex_str) {
try {
return new bytearray_t(salticidae::from_hex(hex_str));
@@ -141,6 +149,14 @@ bytearray_t *bytearray_new_from_hex(const char *hex_str) {
}
}
+bytearray_t *bytearray_new_from_bytes(const uint8_t *arr, size_t len) {
+ try {
+ return new bytearray_t(arr, arr + len);
+ } catch (...) {
+ return nullptr;
+ }
+}
+
char *datastream_get_hex(datastream_t *self) {
std::string tmp = self->get_hex();
auto res = (char *)malloc(tmp.length() + 1);