aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-13 16:51:35 -0400
committerDeterminant <[email protected]>2019-06-13 16:51:35 -0400
commit76e6831168a25bc3aba8802f1586d0a0ab0dc4a2 (patch)
treefcd283a62977d00e480421dfef8dc58cf08273aa /include
parentd164d2d4535468bf695ff6c0f277486e6016e586 (diff)
add del_peer
Diffstat (limited to 'include')
-rw-r--r--include/salticidae/conn.h2
-rw-r--r--include/salticidae/network.h31
-rw-r--r--include/salticidae/util.h2
3 files changed, 30 insertions, 5 deletions
diff --git a/include/salticidae/conn.h b/include/salticidae/conn.h
index 546df5f..62825db 100644
--- a/include/salticidae/conn.h
+++ b/include/salticidae/conn.h
@@ -266,7 +266,7 @@ class ConnPool {
protected:
conn_t _connect(const NetAddr &addr);
void _listen(NetAddr listen_addr);
- void recoverable_error(const std::exception_ptr err) {
+ void recoverable_error(const std::exception_ptr err) const {
user_tcall->async_call([this, err](ThreadCall::Handle &) {
if (error_cb) {
try {
diff --git a/include/salticidae/network.h b/include/salticidae/network.h
index 14d270f..1095c89 100644
--- a/include/salticidae/network.h
+++ b/include/salticidae/network.h
@@ -426,6 +426,7 @@ class PeerNetwork: public MsgNetwork<OpcodeType> {
~PeerNetwork() { this->stop_workers(); }
void add_peer(const NetAddr &paddr);
+ void del_peer(const NetAddr &paddr);
bool has_peer(const NetAddr &paddr) const;
const conn_t get_peer_conn(const NetAddr &paddr) const;
using MsgNet::send_msg;
@@ -725,6 +726,23 @@ void PeerNetwork<O, _, __>::add_peer(const NetAddr &addr) {
throw PeerNetworkError(SALTI_ERROR_PEER_ALREADY_EXISTS);
id2peer.insert(std::make_pair(addr, new Peer(addr, nullptr, this->disp_ec)));
start_active_conn(addr);
+ } catch (const PeerNetworkError &) {
+ this->recoverable_error(std::current_exception());
+ } catch (...) { this->disp_error_cb(std::current_exception()); }
+ });
+}
+
+template<typename O, O _, O __>
+void PeerNetwork<O, _, __>::del_peer(const NetAddr &addr) {
+ this->disp_tcall->async_call([this, addr](ThreadCall::Handle &) {
+ try {
+ auto it = id2peer.find(addr);
+ if (it == id2peer.end())
+ throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXIST);
+ it->second->conn->disp_terminate();
+ id2peer.erase(it);
+ } catch (const PeerNetworkError &) {
+ this->recoverable_error(std::current_exception());
} catch (...) { this->disp_error_cb(std::current_exception()); }
});
}
@@ -739,8 +757,10 @@ PeerNetwork<O, _, __>::get_peer_conn(const NetAddr &paddr) const {
try {
auto it = id2peer.find(paddr);
if (it == id2peer.end())
- throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXISTS);
+ throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXIST);
conn = it->second->conn;
+ } catch (const PeerNetworkError &) {
+ this->recoverable_error(std::current_exception());
} catch (...) {
err = std::current_exception();
}
@@ -771,8 +791,10 @@ void PeerNetwork<O, _, __>::_send_msg(Msg &&msg, const NetAddr &paddr) {
try {
auto it = id2peer.find(paddr);
if (it == id2peer.end())
- throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXISTS);
+ throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXIST);
this->_send_msg_dispatcher(msg, it->second->conn);
+ } catch (const PeerNetworkError &) {
+ this->recoverable_error(std::current_exception());
} catch (...) { this->recoverable_error(std::current_exception()); }
});
}
@@ -792,9 +814,11 @@ void PeerNetwork<O, _, __>::_multicast_msg(Msg &&msg, const std::vector<NetAddr>
{
auto it = id2peer.find(addr);
if (it == id2peer.end())
- throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXISTS);
+ throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXIST);
this->_send_msg_dispatcher(msg, it->second->conn);
}
+ } catch (const PeerNetworkError &) {
+ this->recoverable_error(std::current_exception());
} catch (...) { this->recoverable_error(std::current_exception()); }
});
}
@@ -925,6 +949,7 @@ msgnetwork_config_t *peernetwork_config_as_msgnetwork_config(peernetwork_config_
peernetwork_t *peernetwork_new(const eventcontext_t *ec, const peernetwork_config_t *config);
void peernetwork_free(const peernetwork_t *self);
void peernetwork_add_peer(peernetwork_t *self, const netaddr_t *paddr);
+void peernetwork_del_peer(peernetwork_t *self, const netaddr_t *paddr);
bool peernetwork_has_peer(const peernetwork_t *self, const netaddr_t *paddr);
const peernetwork_conn_t *peernetwork_get_peer_conn(const peernetwork_t *self, const netaddr_t *paddr);
msgnetwork_t *peernetwork_as_msgnetwork(peernetwork_t *self);
diff --git a/include/salticidae/util.h b/include/salticidae/util.h
index 0ddf5be..41f681c 100644
--- a/include/salticidae/util.h
+++ b/include/salticidae/util.h
@@ -60,7 +60,7 @@ enum SalticidaeErrorCode {
SALTI_ERROR_LISTEN,
SALTI_ERROR_CONNECT,
SALTI_ERROR_PEER_ALREADY_EXISTS,
- SALTI_ERROR_PEER_NOT_EXISTS,
+ SALTI_ERROR_PEER_NOT_EXIST,
SALTI_ERROR_NETADDR_INVALID,
SALTI_ERROR_OPTVAL_INVALID,
SALTI_ERROR_OPTNAME_ALREADY_EXISTS,