diff options
Diffstat (limited to 'src/sp/protocol/reqrep0')
| -rw-r--r-- | src/sp/protocol/reqrep0/rep.c | 53 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/req.c | 5 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xrep.c | 19 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xreq.c | 17 |
4 files changed, 53 insertions, 41 deletions
diff --git a/src/sp/protocol/reqrep0/rep.c b/src/sp/protocol/reqrep0/rep.c index a15488c0..8559ebeb 100644 --- a/src/sp/protocol/reqrep0/rep.c +++ b/src/sp/protocol/reqrep0/rep.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -26,11 +26,11 @@ static void rep0_pipe_recv_cb(void *); static void rep0_pipe_fini(void *); struct rep0_ctx { - rep0_sock * sock; + rep0_sock *sock; uint32_t pipe_id; - rep0_pipe * spipe; // send pipe - nni_aio * saio; // send aio - nni_aio * raio; // recv aio + rep0_pipe *spipe; // send pipe + nni_aio *saio; // send aio + nni_aio *raio; // recv aio nni_list_node sqnode; nni_list_node rqnode; size_t btrace_len; @@ -51,8 +51,8 @@ struct rep0_sock { // rep0_pipe is our per-pipe protocol private structure. struct rep0_pipe { - nni_pipe * pipe; - rep0_sock * rep; + nni_pipe *pipe; + rep0_sock *rep; uint32_t id; nni_aio aio_send; nni_aio aio_recv; @@ -65,9 +65,9 @@ struct rep0_pipe { static void rep0_ctx_close(void *arg) { - rep0_ctx * ctx = arg; + rep0_ctx *ctx = arg; rep0_sock *s = ctx->sock; - nni_aio * aio; + nni_aio *aio; nni_mtx_lock(&s->lk); if ((aio = ctx->saio) != NULL) { @@ -97,7 +97,7 @@ static void rep0_ctx_init(void *carg, void *sarg) { rep0_sock *s = sarg; - rep0_ctx * ctx = carg; + rep0_ctx *ctx = carg; NNI_LIST_NODE_INIT(&ctx->sqnode); NNI_LIST_NODE_INIT(&ctx->rqnode); @@ -109,7 +109,7 @@ rep0_ctx_init(void *carg, void *sarg) static void rep0_ctx_cancel_send(nni_aio *aio, void *arg, int rv) { - rep0_ctx * ctx = arg; + rep0_ctx *ctx = arg; rep0_sock *s = ctx->sock; nni_mtx_lock(&s->lk); @@ -128,10 +128,10 @@ rep0_ctx_cancel_send(nni_aio *aio, void *arg, int rv) static void rep0_ctx_send(void *arg, nni_aio *aio) { - rep0_ctx * ctx = arg; + rep0_ctx *ctx = arg; rep0_sock *s = ctx->sock; rep0_pipe *p; - nni_msg * msg; + nni_msg *msg; int rv; size_t len; uint32_t p_id; // pipe id @@ -264,7 +264,7 @@ static void rep0_pipe_fini(void *arg) { rep0_pipe *p = arg; - nng_msg * msg; + nng_msg *msg; if ((msg = nni_aio_get_msg(&p->aio_recv)) != NULL) { nni_aio_set_msg(&p->aio_recv, NULL); @@ -300,6 +300,9 @@ rep0_pipe_start(void *arg) if (nni_pipe_peer(p->pipe) != NNG_REP0_PEER) { // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNG_REP0_PEER); return (NNG_EPROTO); } @@ -320,7 +323,7 @@ rep0_pipe_close(void *arg) { rep0_pipe *p = arg; rep0_sock *s = p->rep; - rep0_ctx * ctx; + rep0_ctx *ctx; nni_aio_close(&p->aio_send); nni_aio_close(&p->aio_recv); @@ -358,9 +361,9 @@ rep0_pipe_send_cb(void *arg) { rep0_pipe *p = arg; rep0_sock *s = p->rep; - rep0_ctx * ctx; - nni_aio * aio; - nni_msg * msg; + rep0_ctx *ctx; + nni_aio *aio; + nni_msg *msg; size_t len; if (nni_aio_result(&p->aio_send) != 0) { @@ -400,7 +403,7 @@ rep0_pipe_send_cb(void *arg) static void rep0_cancel_recv(nni_aio *aio, void *arg, int rv) { - rep0_ctx * ctx = arg; + rep0_ctx *ctx = arg; rep0_sock *s = ctx->sock; nni_mtx_lock(&s->lk); @@ -415,11 +418,11 @@ rep0_cancel_recv(nni_aio *aio, void *arg, int rv) static void rep0_ctx_recv(void *arg, nni_aio *aio) { - rep0_ctx * ctx = arg; + rep0_ctx *ctx = arg; rep0_sock *s = ctx->sock; rep0_pipe *p; size_t len; - nni_msg * msg; + nni_msg *msg; if (nni_aio_begin(aio) != 0) { return; @@ -472,10 +475,10 @@ rep0_pipe_recv_cb(void *arg) { rep0_pipe *p = arg; rep0_sock *s = p->rep; - rep0_ctx * ctx; - nni_msg * msg; - uint8_t * body; - nni_aio * aio; + rep0_ctx *ctx; + nni_msg *msg; + uint8_t *body; + nni_aio *aio; size_t len; int hops; int ttl; diff --git a/src/sp/protocol/reqrep0/req.c b/src/sp/protocol/reqrep0/req.c index 35c496f0..416b6fb7 100644 --- a/src/sp/protocol/reqrep0/req.c +++ b/src/sp/protocol/reqrep0/req.c @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -197,6 +197,9 @@ req0_pipe_start(void *arg) req0_sock *s = p->req; if (nni_pipe_peer(p->pipe) != NNG_REQ0_PEER) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNG_REQ0_PEER); return (NNG_EPROTO); } diff --git a/src/sp/protocol/reqrep0/xrep.c b/src/sp/protocol/reqrep0/xrep.c index 9241dccd..7e259dfc 100644 --- a/src/sp/protocol/reqrep0/xrep.c +++ b/src/sp/protocol/reqrep0/xrep.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -29,8 +29,8 @@ static void xrep0_pipe_fini(void *); // xrep0_sock is our per-socket protocol private structure. struct xrep0_sock { - nni_msgq * uwq; - nni_msgq * urq; + nni_msgq *uwq; + nni_msgq *urq; nni_mtx lk; nni_atomic_int ttl; nni_id_map pipes; @@ -39,9 +39,9 @@ struct xrep0_sock { // xrep0_pipe is our per-pipe protocol private structure. struct xrep0_pipe { - nni_pipe * pipe; + nni_pipe *pipe; xrep0_sock *rep; - nni_msgq * sendq; + nni_msgq *sendq; nni_aio aio_getq; nni_aio aio_send; nni_aio aio_recv; @@ -155,6 +155,9 @@ xrep0_pipe_start(void *arg) if (nni_pipe_peer(p->pipe) != NNG_REP0_PEER) { // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNG_REP0_PEER); return (NNG_EPROTO); } @@ -191,8 +194,8 @@ static void xrep0_sock_getq_cb(void *arg) { xrep0_sock *s = arg; - nni_msgq * uwq = s->uwq; - nni_msg * msg; + nni_msgq *uwq = s->uwq; + nni_msg *msg; uint32_t id; xrep0_pipe *p; @@ -270,7 +273,7 @@ xrep0_pipe_recv_cb(void *arg) { xrep0_pipe *p = arg; xrep0_sock *s = p->rep; - nni_msg * msg; + nni_msg *msg; int hops; int ttl; diff --git a/src/sp/protocol/reqrep0/xreq.c b/src/sp/protocol/reqrep0/xreq.c index 787c230d..b0ff301b 100644 --- a/src/sp/protocol/reqrep0/xreq.c +++ b/src/sp/protocol/reqrep0/xreq.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -21,14 +21,14 @@ typedef struct xreq0_sock xreq0_sock; // An xreq0_sock is our per-socket protocol private structure. struct xreq0_sock { - nni_msgq * uwq; - nni_msgq * urq; + nni_msgq *uwq; + nni_msgq *urq; nni_atomic_int ttl; }; // A req0_pipe is our per-pipe protocol private structure. struct xreq0_pipe { - nni_pipe * pipe; + nni_pipe *pipe; xreq0_sock *req; nni_aio aio_getq; nni_aio aio_send; @@ -115,6 +115,9 @@ xreq0_pipe_start(void *arg) xreq0_sock *s = p->req; if (nni_pipe_peer(p->pipe) != NNG_REQ0_PEER) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNG_REQ0_PEER); return (NNG_EPROTO); } @@ -193,7 +196,7 @@ xreq0_recv_cb(void *arg) { xreq0_pipe *p = arg; xreq0_sock *sock = p->req; - nni_msg * msg; + nni_msg *msg; bool end; if (nni_aio_result(&p->aio_recv) != 0) { @@ -218,7 +221,7 @@ xreq0_recv_cb(void *arg) body = nni_msg_body(msg); end = ((body[0] & 0x80u) != 0); - if (nng_msg_header_append(msg, body, sizeof (uint32_t)) != 0) { + if (nng_msg_header_append(msg, body, sizeof(uint32_t)) != 0) { // TODO: bump a no-memory stat nni_msg_free(msg); // Closing the pipe may release some memory. @@ -227,7 +230,7 @@ xreq0_recv_cb(void *arg) nni_pipe_close(p->pipe); return; } - nni_msg_trim(msg, sizeof (uint32_t)); + nni_msg_trim(msg, sizeof(uint32_t)); } nni_aio_set_msg(&p->aio_putq, msg); nni_msgq_aio_put(sock->urq, &p->aio_putq); |
