diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-03-01 06:42:05 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-03-01 06:42:05 +0100 |
commit | 68bb9f39967ca45166bd070ee1f3fa1304cb6e98 (patch) | |
tree | a3d57ca1bb2c5e5fc54a784ee1239f1b1167b0d8 | |
parent | e5415f2b024119a8f32879db10976336d56ae1bc (diff) | |
download | fastd-68bb9f39967ca45166bd070ee1f3fa1304cb6e98.tar fastd-68bb9f39967ca45166bd070ee1f3fa1304cb6e98.zip |
Identify peers be key in log output when no name is available
-rw-r--r-- | src/fastd.h | 1 | ||||
-rw-r--r-- | src/printf.c | 12 | ||||
-rw-r--r-- | src/protocol_ec25519_fhmqvc.c | 14 |
3 files changed, 24 insertions, 3 deletions
diff --git a/src/fastd.h b/src/fastd.h index 391b47a..880b6f0 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -82,6 +82,7 @@ struct fastd_protocol { void (*generate_key)(fastd_context_t *ctx); void (*show_key)(fastd_context_t *ctx); void (*set_shell_env)(fastd_context_t *ctx, const fastd_peer_t *peer); + bool (*describe_peer)(const fastd_context_t *ctx, const fastd_peer_t *peer, char *buf, size_t len); }; struct fastd_method { diff --git a/src/printf.c b/src/printf.c index e55ae20..bd06727 100644 --- a/src/printf.c +++ b/src/printf.c @@ -67,10 +67,16 @@ static int snprint_peer_address(const fastd_context_t *ctx, char *buffer, size_t } static int snprint_peer_str(const fastd_context_t *ctx, char *buffer, size_t size, const fastd_peer_t *peer) { - if (peer->config && peer->config->name) + if (peer->config && peer->config->name) { return snprintf_safe(buffer, size, "<%s>", peer->config->name); - else - return snprintf_safe(buffer, size, "<(null)>"); + } + else { + char buf[65]; + if (ctx->conf->protocol->describe_peer(ctx, peer, buf, sizeof(buf))) + return snprintf_safe(buffer, size, "{%s}", buf); + else + return snprintf_safe(buffer, size, "(null)"); + } } int fastd_vsnprintf(const fastd_context_t *ctx, char *buffer, size_t size, const char *format, va_list ap) { diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c index 061726f..2bf6bde 100644 --- a/src/protocol_ec25519_fhmqvc.c +++ b/src/protocol_ec25519_fhmqvc.c @@ -901,6 +901,19 @@ static void protocol_set_shell_env(fastd_context_t *ctx, const fastd_peer_t *pee } } +static bool protocol_describe_peer(const fastd_context_t *ctx, const fastd_peer_t *peer, char *buf, size_t len) { + if (peer && peer->protocol_config) { + char dumpbuf[65]; + + hexdump(dumpbuf, peer->protocol_config->public_key.p); + snprintf(buf, len, "%.16s", dumpbuf); + return true; + } + else { + return false; + } +} + const fastd_protocol_t fastd_protocol_ec25519_fhmqvc = { .name = "ec25519-fhmqvc", @@ -920,4 +933,5 @@ const fastd_protocol_t fastd_protocol_ec25519_fhmqvc = { .generate_key = protocol_generate_key, .show_key = protocol_show_key, .set_shell_env = protocol_set_shell_env, + .describe_peer = protocol_describe_peer, }; |