From 82b322a37bcf890275f91b56a9a0347be056be9d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 14 Apr 2024 15:43:59 -0700 Subject: Log protocol connections rejected by protocol. --- src/sp/protocol/bus0/bus.c | 5 +++- src/sp/protocol/pair0/pair.c | 9 ++++++- src/sp/protocol/pair1/pair.c | 8 +++++- src/sp/protocol/pair1/pair1_poly.c | 25 ++++++++++-------- src/sp/protocol/pipeline0/pull.c | 19 ++++++++------ src/sp/protocol/pipeline0/push.c | 5 +++- src/sp/protocol/pubsub0/pub.c | 5 +++- src/sp/protocol/pubsub0/sub.c | 5 +++- src/sp/protocol/pubsub0/xsub.c | 13 ++++++---- src/sp/protocol/reqrep0/rep.c | 53 ++++++++++++++++++++------------------ src/sp/protocol/reqrep0/req.c | 5 +++- src/sp/protocol/reqrep0/xrep.c | 19 ++++++++------ src/sp/protocol/reqrep0/xreq.c | 17 +++++++----- src/sp/protocol/survey0/respond.c | 51 +++++++++++++++++++----------------- src/sp/protocol/survey0/survey.c | 45 +++++++++++++++++--------------- src/sp/protocol/survey0/xrespond.c | 19 ++++++++------ src/sp/protocol/survey0/xsurvey.c | 19 ++++++++------ 17 files changed, 190 insertions(+), 132 deletions(-) (limited to 'src') diff --git a/src/sp/protocol/bus0/bus.c b/src/sp/protocol/bus0/bus.c index faa94c13..692cb250 100644 --- a/src/sp/protocol/bus0/bus.c +++ b/src/sp/protocol/bus0/bus.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -157,6 +157,9 @@ bus0_pipe_start(void *arg) bus0_sock *s = p->bus; if (nni_pipe_peer(p->pipe) != NNI_PROTO_BUS_V0) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer pipe protocol %d is not BUS protocol, rejected.", + nni_pipe_peer(p->pipe)); return (NNG_EPROTO); } diff --git a/src/sp/protocol/pair0/pair.c b/src/sp/protocol/pair0/pair.c index e272fd2e..558a9e3b 100644 --- a/src/sp/protocol/pair0/pair.c +++ b/src/sp/protocol/pair0/pair.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -11,6 +11,7 @@ #include #include "core/nng_impl.h" +#include "core/pipe.h" #include "nng/protocol/pair0/pair.h" // Pair protocol. The PAIR protocol is a simple 1:1 messaging pattern. @@ -157,12 +158,18 @@ pair0_pipe_start(void *arg) if (nni_pipe_peer(p->pipe) != NNI_PROTO_PAIR_V0) { // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNI_PROTO_PAIR_V0); return (NNG_EPROTO); } nni_mtx_lock(&s->mtx); if (s->p != NULL) { nni_mtx_unlock(&s->mtx); + nng_log_warn("NNG-PAIR-BUSY", + "Peer pipe protocol %d is already paired, rejected.", + nni_pipe_peer(p->pipe)); return (NNG_EBUSY); // Already have a peer, denied. } s->p = p; diff --git a/src/sp/protocol/pair1/pair.c b/src/sp/protocol/pair1/pair.c index 401d70d5..1704d537 100644 --- a/src/sp/protocol/pair1/pair.c +++ b/src/sp/protocol/pair1/pair.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -265,12 +265,18 @@ pair1_pipe_start(void *arg) if (nni_pipe_peer(p->pipe) != NNG_PAIR1_PEER) { BUMP_STAT(&s->stat_reject_mismatch); // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNG_PAIR1_PEER); return (NNG_EPROTO); } nni_mtx_lock(&s->mtx); if (s->p != NULL) { nni_mtx_unlock(&s->mtx); + nng_log_warn("NNG-PAIR-BUSY", + "Peer pipe protocol %d is already paired, rejected.", + nni_pipe_peer(p->pipe)); BUMP_STAT(&s->stat_reject_already); return (NNG_EBUSY); } diff --git a/src/sp/protocol/pair1/pair1_poly.c b/src/sp/protocol/pair1/pair1_poly.c index 06afc57a..546d3138 100644 --- a/src/sp/protocol/pair1/pair1_poly.c +++ b/src/sp/protocol/pair1/pair1_poly.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -39,9 +39,9 @@ static void pair1poly_pipe_fini(void *); // pair1poly_sock is our per-socket protocol private structure. struct pair1poly_sock { - nni_msgq * uwq; - nni_msgq * urq; - nni_sock * sock; + nni_msgq *uwq; + nni_msgq *urq; + nni_sock *sock; nni_atomic_int ttl; nni_mtx mtx; nni_id_map pipes; @@ -60,9 +60,9 @@ struct pair1poly_sock { // pair1poly_pipe is our per-pipe protocol private structure. struct pair1poly_pipe { - nni_pipe * pipe; + nni_pipe *pipe; pair1poly_sock *pair; - nni_msgq * send_queue; + nni_msgq *send_queue; nni_aio aio_send; nni_aio aio_recv; nni_aio aio_get; @@ -230,9 +230,12 @@ pair1poly_pipe_start(void *arg) nni_mtx_lock(&s->mtx); if (nni_pipe_peer(p->pipe) != NNG_PAIR1_PEER) { + // Peer protocol mismatch. nni_mtx_unlock(&s->mtx); BUMP_STAT(&s->stat_reject_mismatch); - // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNG_PAIR1_PEER); return (NNG_EPROTO); } @@ -284,9 +287,9 @@ pair1poly_pipe_recv_cb(void *arg) { pair1poly_pipe *p = arg; pair1poly_sock *s = p->pair; - nni_msg * msg; + nni_msg *msg; uint32_t hdr; - nni_pipe * pipe = p->pipe; + nni_pipe *pipe = p->pipe; size_t len; if (nni_aio_result(&p->aio_recv) != 0) { @@ -334,7 +337,7 @@ pair1poly_sock_get_cb(void *arg) { pair1poly_pipe *p; pair1poly_sock *s = arg; - nni_msg * msg; + nni_msg *msg; uint32_t id; if (nni_aio_result(&s->aio_get) != 0) { @@ -386,7 +389,7 @@ static void pair1poly_pipe_get_cb(void *arg) { pair1poly_pipe *p = arg; - nni_msg * msg; + nni_msg *msg; if (nni_aio_result(&p->aio_get) != 0) { nni_pipe_close(p->pipe); diff --git a/src/sp/protocol/pipeline0/pull.c b/src/sp/protocol/pipeline0/pull.c index 07d55405..40dd514c 100644 --- a/src/sp/protocol/pipeline0/pull.c +++ b/src/sp/protocol/pipeline0/pull.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -39,9 +39,9 @@ struct pull0_sock { // pull0_pipe is our per-pipe protocol private structure. struct pull0_pipe { - nni_pipe * p; - pull0_sock * s; - nni_msg * m; + nni_pipe *p; + pull0_sock *s; + nni_msg *m; nni_aio aio; bool closed; nni_list_node node; @@ -104,6 +104,9 @@ pull0_pipe_start(void *arg) if (nni_pipe_peer(p->p) != NNI_PROTO_PUSH_V0) { // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->p), NNI_PROTO_PUSH_V0); return (NNG_EPROTO); } @@ -137,9 +140,9 @@ pull0_recv_cb(void *arg) { pull0_pipe *p = arg; pull0_sock *s = p->s; - nni_aio * ap = &p->aio; - nni_aio * as; - nni_msg * m; + nni_aio *ap = &p->aio; + nni_aio *as; + nni_msg *m; if (nni_aio_result(ap) != 0) { // Failed to get a message, probably the pipe is closed. @@ -185,7 +188,7 @@ static void pull0_sock_close(void *arg) { pull0_sock *s = arg; - nni_aio * a; + nni_aio *a; nni_mtx_lock(&s->m); while ((a = nni_list_first(&s->rq)) != NULL) { nni_aio_list_remove(a); diff --git a/src/sp/protocol/pipeline0/push.c b/src/sp/protocol/pipeline0/push.c index 284af5aa..0bd57d0a 100644 --- a/src/sp/protocol/pipeline0/push.c +++ b/src/sp/protocol/pipeline0/push.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -129,6 +129,9 @@ push0_pipe_start(void *arg) push0_pipe *p = arg; if (nni_pipe_peer(p->pipe) != NNI_PROTO_PULL_V0) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNI_PROTO_PULL_V0); return (NNG_EPROTO); } diff --git a/src/sp/protocol/pubsub0/pub.c b/src/sp/protocol/pubsub0/pub.c index b0a9ef07..9539b851 100644 --- a/src/sp/protocol/pubsub0/pub.c +++ b/src/sp/protocol/pubsub0/pub.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -135,6 +135,9 @@ pub0_pipe_start(void *arg) pub0_sock *sock = p->pub; if (nni_pipe_peer(p->pipe) != NNI_PROTO_SUB_V0) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNI_PROTO_SUB_V0); return (NNG_EPROTO); } nni_mtx_lock(&sock->mtx); diff --git a/src/sp/protocol/pubsub0/sub.c b/src/sp/protocol/pubsub0/sub.c index e7540dee..ee911153 100644 --- a/src/sp/protocol/pubsub0/sub.c +++ b/src/sp/protocol/pubsub0/sub.c @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Nathan Kent // @@ -274,6 +274,9 @@ sub0_pipe_start(void *arg) if (nni_pipe_peer(p->pipe) != NNI_PROTO_PUB_V0) { // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNI_PROTO_PUB_V0); return (NNG_EPROTO); } diff --git a/src/sp/protocol/pubsub0/xsub.c b/src/sp/protocol/pubsub0/xsub.c index ad060087..abcdf8c9 100644 --- a/src/sp/protocol/pubsub0/xsub.c +++ b/src/sp/protocol/pubsub0/xsub.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -39,9 +39,9 @@ struct xsub0_sock { // sub0_pipe is our per-pipe protocol private structure. struct xsub0_pipe { - nni_pipe * pipe; + nni_pipe *pipe; xsub0_sock *sub; - nni_aio aio_recv; + nni_aio aio_recv; }; static void @@ -106,6 +106,9 @@ xsub0_pipe_start(void *arg) if (nni_pipe_peer(p->pipe) != NNI_PROTO_PUB_V0) { // Peer protocol mismatch. + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNI_PROTO_PUB_V0); return (NNG_EPROTO); } @@ -126,8 +129,8 @@ xsub0_recv_cb(void *arg) { xsub0_pipe *p = arg; xsub0_sock *s = p->sub; - nni_msgq * urq = s->urq; - nni_msg * msg; + nni_msgq *urq = s->urq; + nni_msg *msg; if (nni_aio_result(&p->aio_recv) != 0) { nni_pipe_close(p->pipe); 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. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // 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. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // 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. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // 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. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // 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); diff --git a/src/sp/protocol/survey0/respond.c b/src/sp/protocol/survey0/respond.c index d29eab97..8a8c134b 100644 --- a/src/sp/protocol/survey0/respond.c +++ b/src/sp/protocol/survey0/respond.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -35,11 +35,11 @@ static void resp0_pipe_recv_cb(void *); static void resp0_pipe_fini(void *); struct resp0_ctx { - resp0_sock * sock; + resp0_sock *sock; uint32_t pipe_id; - resp0_pipe * spipe; // send pipe - nni_aio * saio; // send aio - nni_aio * raio; // recv aio + resp0_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; @@ -60,8 +60,8 @@ struct resp0_sock { // resp0_pipe is our per-pipe protocol private structure. struct resp0_pipe { - nni_pipe * npipe; - resp0_sock * psock; + nni_pipe *npipe; + resp0_sock *psock; bool busy; bool closed; uint32_t id; @@ -74,9 +74,9 @@ struct resp0_pipe { static void resp0_ctx_close(void *arg) { - resp0_ctx * ctx = arg; + resp0_ctx *ctx = arg; resp0_sock *s = ctx->sock; - nni_aio * aio; + nni_aio *aio; // complete any outstanding operations here, cancellation, etc. @@ -108,7 +108,7 @@ static void resp0_ctx_init(void *carg, void *sarg) { resp0_sock *s = sarg; - resp0_ctx * ctx = carg; + resp0_ctx *ctx = carg; NNI_LIST_NODE_INIT(&ctx->sqnode); NNI_LIST_NODE_INIT(&ctx->rqnode); @@ -120,7 +120,7 @@ resp0_ctx_init(void *carg, void *sarg) static void resp0_ctx_cancel_send(nni_aio *aio, void *arg, int rv) { - resp0_ctx * ctx = arg; + resp0_ctx *ctx = arg; resp0_sock *s = ctx->sock; nni_mtx_lock(&s->mtx); @@ -138,10 +138,10 @@ resp0_ctx_cancel_send(nni_aio *aio, void *arg, int rv) static void resp0_ctx_send(void *arg, nni_aio *aio) { - resp0_ctx * ctx = arg; + resp0_ctx *ctx = arg; resp0_sock *s = ctx->sock; resp0_pipe *p; - nni_msg * msg; + nni_msg *msg; size_t len; uint32_t pid; int rv; @@ -269,7 +269,7 @@ static void resp0_pipe_fini(void *arg) { resp0_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); @@ -305,6 +305,9 @@ resp0_pipe_start(void *arg) int rv; if (nni_pipe_peer(p->npipe) != NNI_PROTO_SURVEYOR_V0) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->npipe), NNI_PROTO_SURVEYOR_V0); return (NNG_EPROTO); } @@ -324,7 +327,7 @@ resp0_pipe_close(void *arg) { resp0_pipe *p = arg; resp0_sock *s = p->psock; - resp0_ctx * ctx; + resp0_ctx *ctx; nni_aio_close(&p->aio_send); nni_aio_close(&p->aio_recv); @@ -356,9 +359,9 @@ resp0_pipe_send_cb(void *arg) { resp0_pipe *p = arg; resp0_sock *s = p->psock; - resp0_ctx * ctx; - nni_aio * aio; - nni_msg * msg; + resp0_ctx *ctx; + nni_aio *aio; + nni_msg *msg; size_t len; if (nni_aio_result(&p->aio_send) != 0) { @@ -398,7 +401,7 @@ resp0_pipe_send_cb(void *arg) static void resp0_cancel_recv(nni_aio *aio, void *arg, int rv) { - resp0_ctx * ctx = arg; + resp0_ctx *ctx = arg; resp0_sock *s = ctx->sock; nni_mtx_lock(&s->mtx); @@ -413,11 +416,11 @@ resp0_cancel_recv(nni_aio *aio, void *arg, int rv) static void resp0_ctx_recv(void *arg, nni_aio *aio) { - resp0_ctx * ctx = arg; + resp0_ctx *ctx = arg; resp0_sock *s = ctx->sock; resp0_pipe *p; size_t len; - nni_msg * msg; + nni_msg *msg; if (nni_aio_begin(aio) != 0) { return; @@ -470,9 +473,9 @@ resp0_pipe_recv_cb(void *arg) { resp0_pipe *p = arg; resp0_sock *s = p->psock; - resp0_ctx * ctx; - nni_msg * msg; - nni_aio * aio; + resp0_ctx *ctx; + nni_msg *msg; + nni_aio *aio; int hops; size_t len; int ttl; diff --git a/src/sp/protocol/survey0/survey.c b/src/sp/protocol/survey0/survey.c index dc7346c7..3197f743 100644 --- a/src/sp/protocol/survey0/survey.c +++ b/src/sp/protocol/survey0/survey.c @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -27,7 +27,7 @@ static void surv0_pipe_send_cb(void *); static void surv0_pipe_recv_cb(void *); struct surv0_ctx { - surv0_sock * sock; + surv0_sock *sock; uint32_t survey_id; // survey id nni_lmq recv_lmq; nni_list recv_queue; @@ -51,8 +51,8 @@ struct surv0_sock { // surv0_pipe is our per-pipe protocol private structure. struct surv0_pipe { - nni_pipe * pipe; - surv0_sock * sock; + nni_pipe *pipe; + surv0_sock *sock; nni_lmq send_queue; nni_list_node node; nni_aio aio_send; @@ -64,7 +64,7 @@ struct surv0_pipe { static void surv0_ctx_abort(surv0_ctx *ctx, int err) { - nni_aio * aio; + nni_aio *aio; surv0_sock *sock = ctx->sock; while ((aio = nni_list_first(&ctx->recv_queue)) != NULL) { @@ -103,8 +103,8 @@ surv0_ctx_fini(void *arg) static void surv0_ctx_init(void *c, void *s) { - surv0_ctx * ctx = c; - surv0_sock * sock = s; + surv0_ctx *ctx = c; + surv0_sock *sock = s; int len; nng_duration tmo; @@ -131,7 +131,7 @@ surv0_ctx_init(void *c, void *s) static void surv0_ctx_cancel(nni_aio *aio, void *arg, int rv) { - surv0_ctx * ctx = arg; + surv0_ctx *ctx = arg; surv0_sock *sock = ctx->sock; nni_mtx_lock(&sock->mtx); if (nni_list_active(&ctx->recv_queue, aio)) { @@ -148,10 +148,10 @@ surv0_ctx_cancel(nni_aio *aio, void *arg, int rv) static void surv0_ctx_recv(void *arg, nni_aio *aio) { - surv0_ctx * ctx = arg; - surv0_sock *sock = ctx->sock; - nni_msg * msg; - nni_time now; + surv0_ctx *ctx = arg; + surv0_sock *sock = ctx->sock; + nni_msg *msg; + nni_time now; nni_duration timeout; if (nni_aio_begin(aio) != 0) { @@ -200,10 +200,10 @@ again: static void surv0_ctx_send(void *arg, nni_aio *aio) { - surv0_ctx * ctx = arg; - surv0_sock * sock = ctx->sock; - surv0_pipe * pipe; - nni_msg * msg = nni_aio_get_msg(aio); + surv0_ctx *ctx = arg; + surv0_sock *sock = ctx->sock; + surv0_pipe *pipe; + nni_msg *msg = nni_aio_get_msg(aio); size_t len = nni_msg_len(msg); nng_duration survey_time; int rv; @@ -360,6 +360,9 @@ surv0_pipe_start(void *arg) surv0_sock *s = p->sock; if (nni_pipe_peer(p->pipe) != NNG_SURVEYOR0_PEER) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->pipe), NNG_SURVEYOR0_PEER); return (NNG_EPROTO); } @@ -394,7 +397,7 @@ surv0_pipe_send_cb(void *arg) { surv0_pipe *p = arg; surv0_sock *sock = p->sock; - nni_msg * msg; + nni_msg *msg; if (nni_aio_result(&p->aio_send) != 0) { nni_msg_free(nni_aio_get_msg(&p->aio_send)); @@ -422,10 +425,10 @@ surv0_pipe_recv_cb(void *arg) { surv0_pipe *p = arg; surv0_sock *sock = p->sock; - surv0_ctx * ctx; - nni_msg * msg; + surv0_ctx *ctx; + nni_msg *msg; uint32_t id; - nni_aio * aio; + nni_aio *aio; if (nni_aio_result(&p->aio_recv) != 0) { nni_pipe_close(p->pipe); @@ -470,7 +473,7 @@ static int surv0_ctx_set_survey_time( void *arg, const void *buf, size_t sz, nni_opt_type t) { - surv0_ctx * ctx = arg; + surv0_ctx *ctx = arg; nng_duration expire; int rv; if ((rv = nni_copyin_ms(&expire, buf, sz, t)) == 0) { diff --git a/src/sp/protocol/survey0/xrespond.c b/src/sp/protocol/survey0/xrespond.c index 81a40486..c4d54594 100644 --- a/src/sp/protocol/survey0/xrespond.c +++ b/src/sp/protocol/survey0/xrespond.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -37,8 +37,8 @@ static void xresp0_pipe_fini(void *); // resp0_sock is our per-socket protocol private structure. struct xresp0_sock { - nni_msgq * urq; - nni_msgq * uwq; + nni_msgq *urq; + nni_msgq *uwq; nni_atomic_int ttl; nni_id_map pipes; nni_aio aio_getq; @@ -47,10 +47,10 @@ struct xresp0_sock { // resp0_pipe is our per-pipe protocol private structure. struct xresp0_pipe { - nni_pipe * npipe; + nni_pipe *npipe; xresp0_sock *psock; uint32_t id; - nni_msgq * sendq; + nni_msgq *sendq; nni_aio aio_getq; nni_aio aio_putq; nni_aio aio_send; @@ -150,6 +150,9 @@ xresp0_pipe_start(void *arg) int rv; if (nni_pipe_peer(p->npipe) != NNI_PROTO_SURVEYOR_V0) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->npipe), NNI_PROTO_SURVEYOR_V0); return (NNG_EPROTO); } @@ -195,7 +198,7 @@ void xresp0_sock_getq_cb(void *arg) { xresp0_sock *s = arg; - nni_msg * msg; + nni_msg *msg; uint32_t id; xresp0_pipe *p; @@ -262,8 +265,8 @@ xresp0_recv_cb(void *arg) { xresp0_pipe *p = arg; xresp0_sock *s = p->psock; - nni_msgq * urq = s->urq; - nni_msg * msg; + nni_msgq *urq = s->urq; + nni_msg *msg; int hops; int ttl; diff --git a/src/sp/protocol/survey0/xsurvey.c b/src/sp/protocol/survey0/xsurvey.c index 3cb3b6bd..208db051 100644 --- a/src/sp/protocol/survey0/xsurvey.c +++ b/src/sp/protocol/survey0/xsurvey.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -27,17 +27,17 @@ static void xsurv0_recv_cb(void *); struct xsurv0_sock { nni_list pipes; nni_aio aio_getq; - nni_msgq * uwq; - nni_msgq * urq; + nni_msgq *uwq; + nni_msgq *urq; nni_mtx mtx; nni_atomic_int ttl; }; // surv0_pipe is our per-pipe protocol private structure. struct xsurv0_pipe { - nni_pipe * npipe; - xsurv0_sock * psock; - nni_msgq * sendq; + nni_pipe *npipe; + xsurv0_sock *psock; + nni_msgq *sendq; nni_list_node node; nni_aio aio_getq; nni_aio aio_putq; @@ -142,6 +142,9 @@ xsurv0_pipe_start(void *arg) xsurv0_sock *s = p->psock; if (nni_pipe_peer(p->npipe) != NNG_SURVEYOR0_PEER) { + nng_log_warn("NNG-PEER-MISMATCH", + "Peer protocol mismatch: %d != %d, rejected.", + nni_pipe_peer(p->npipe), NNG_SURVEYOR0_PEER); return (NNG_EPROTO); } @@ -224,7 +227,7 @@ static void xsurv0_recv_cb(void *arg) { xsurv0_pipe *p = arg; - nni_msg * msg; + nni_msg *msg; bool end; if (nni_aio_result(&p->aio_recv) != 0) { @@ -289,7 +292,7 @@ xsurv0_sock_getq_cb(void *arg) { xsurv0_sock *s = arg; xsurv0_pipe *p; - nni_msg * msg; + nni_msg *msg; if (nni_aio_result(&s->aio_getq) != 0) { // Should be NNG_ECLOSED. -- cgit v1.2.3-70-g09d2