X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeta.c;h=6054427ce62b0d64b8a283f109afc7dfe7a3c3c7;hb=075e6828a7533e7daa790225f17aa6bb39703278;hp=2791ea198c2b4e4471f7e0734a613cff686cc9bf;hpb=1b8f8918360b40a2749d40355266ed7dedbe41b5;p=meshlink diff --git a/src/meta.c b/src/meta.c index 2791ea19..6054427c 100644 --- a/src/meta.c +++ b/src/meta.c @@ -35,7 +35,13 @@ bool send_meta(connection_t *c, const char *buffer, int length) { cp(); - ifdebug(META) logger(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length, c->name, c->hostname); + if(!c) { + logger(LOG_ERR, _("send_meta() called with NULL pointer!")); + abort(); + } + + ifdebug(META) logger(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length, + c->name, c->hostname); /* Add our data to buffer */ if(c->status.encryptout) { @@ -43,13 +49,18 @@ bool send_meta(connection_t *c, const char *buffer, int length) { size_t outlen = length; if(!cipher_encrypt(&c->outcipher, buffer, length, outbuf, &outlen, false) || outlen != length) { - logger(LOG_ERR, _("Error while encrypting metadata to %s (%s)"), c->name, c->hostname); + logger(LOG_ERR, _("Error while encrypting metadata to %s (%s)"), + c->name, c->hostname); return false; } + ifdebug(META) logger(LOG_DEBUG, _("Encrypted write %p %p %p %d"), c, c->buffer, outbuf, length); bufferevent_write(c->buffer, (void *)outbuf, length); + ifdebug(META) logger(LOG_DEBUG, _("Done.")); } else { + ifdebug(META) logger(LOG_DEBUG, _("Unencrypted write %p %p %p %d"), c, c->buffer, buffer, length); bufferevent_write(c->buffer, (void *)buffer, length); + ifdebug(META) logger(LOG_DEBUG, _("Done.")); } return true; @@ -106,14 +117,16 @@ bool receive_meta(connection_t *c) { bufp = endp; } else { size_t outlen = inlen; - evbuffer_expand(c->buffer->input, inlen); + ifdebug(META) logger(LOG_DEBUG, _("Received encrypted %zu bytes"), inlen); + evbuffer_expand(c->buffer->input, c->buffer->input->off + inlen); - if(!cipher_decrypt(&c->incipher, bufp, inlen, c->buffer->input->buffer, &outlen, false) || inlen != outlen) { - logger(LOG_ERR, _("Error while decrypting metadata from %s (%s)"), c->name, c->hostname); + if(!cipher_decrypt(&c->incipher, bufp, inlen, c->buffer->input->buffer + c->buffer->input->off, &outlen, false) || inlen != outlen) { + logger(LOG_ERR, _("Error while decrypting metadata from %s (%s)"), + c->name, c->hostname); return false; } - c->buffer->input->off += inlen; + inlen = 0; }