mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
pong: embed version string into ping replies if DEVELOPER=1.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
85f1a9b825
commit
b8c636514b
@ -1514,22 +1514,13 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
|
|||||||
|
|
||||||
static void handle_pong(struct peer *peer, const u8 *pong)
|
static void handle_pong(struct peer *peer, const u8 *pong)
|
||||||
{
|
{
|
||||||
u8 *ignored;
|
const char *err = got_pong(pong, &peer->num_pings_outstanding);
|
||||||
|
if (err)
|
||||||
status_trace("Got pong!");
|
|
||||||
if (!fromwire_pong(pong, pong, &ignored))
|
|
||||||
peer_failed(&peer->cs,
|
peer_failed(&peer->cs,
|
||||||
peer->gossip_index,
|
peer->gossip_index,
|
||||||
&peer->channel_id,
|
&peer->channel_id,
|
||||||
"Bad pong %s", tal_hex(pong, pong));
|
"%s", err);
|
||||||
|
|
||||||
if (!peer->num_pings_outstanding)
|
|
||||||
peer_failed(&peer->cs,
|
|
||||||
peer->gossip_index,
|
|
||||||
&peer->channel_id,
|
|
||||||
"Unexpected pong");
|
|
||||||
|
|
||||||
peer->num_pings_outstanding--;
|
|
||||||
wire_sync_write(MASTER_FD,
|
wire_sync_write(MASTER_FD,
|
||||||
take(towire_channel_ping_reply(pong, tal_len(pong))));
|
take(towire_channel_ping_reply(pong, tal_len(pong))));
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include <common/ping.h>
|
#include <common/ping.h>
|
||||||
|
#include <common/status.h>
|
||||||
|
#include <common/version.h>
|
||||||
#include <wire/gen_peer_wire.h>
|
#include <wire/gen_peer_wire.h>
|
||||||
|
|
||||||
bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong)
|
bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong)
|
||||||
@ -31,6 +33,10 @@ bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong)
|
|||||||
* as secrets, or portions of initialized memory.
|
* as secrets, or portions of initialized memory.
|
||||||
*/
|
*/
|
||||||
ignored = tal_arrz(ctx, u8, num_pong_bytes);
|
ignored = tal_arrz(ctx, u8, num_pong_bytes);
|
||||||
|
#if DEVELOPER
|
||||||
|
/* Embed version */
|
||||||
|
strncpy((char *)ignored, version(), num_pong_bytes);
|
||||||
|
#endif
|
||||||
*pong = towire_pong(ctx, ignored);
|
*pong = towire_pong(ctx, ignored);
|
||||||
tal_free(ignored);
|
tal_free(ignored);
|
||||||
} else
|
} else
|
||||||
@ -53,3 +59,25 @@ u8 *make_ping(const tal_t *ctx, u16 num_pong_bytes, u16 padlen)
|
|||||||
tal_free(ignored);
|
tal_free(ignored);
|
||||||
return ping;
|
return ping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *got_pong(const u8 *pong, size_t *num_pings_outstanding)
|
||||||
|
{
|
||||||
|
u8 *ignored;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!fromwire_pong(pong, pong, &ignored))
|
||||||
|
return "Bad pong";
|
||||||
|
|
||||||
|
if (*num_pings_outstanding == 0)
|
||||||
|
return "Unexpected pong";
|
||||||
|
|
||||||
|
for (i = 0; i < tal_len(ignored); i++) {
|
||||||
|
if (ignored[i] < ' ' || ignored[i] == 127)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
status_trace("Got pong %zu bytes (%.*s...)",
|
||||||
|
tal_len(ignored), i, (char *)ignored);
|
||||||
|
|
||||||
|
(*num_pings_outstanding)--;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -10,4 +10,7 @@ bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong);
|
|||||||
/* Make a ping packet requesting num_pong_bytes */
|
/* Make a ping packet requesting num_pong_bytes */
|
||||||
u8 *make_ping(const tal_t *ctx, u16 num_pong_bytes, u16 padlen);
|
u8 *make_ping(const tal_t *ctx, u16 num_pong_bytes, u16 padlen);
|
||||||
|
|
||||||
|
/* Returns error string if something wrong. */
|
||||||
|
const char *got_pong(const u8 *pong, size_t *num_pings_outstanding);
|
||||||
|
|
||||||
#endif /* LIGHTNING_COMMON_PING_H */
|
#endif /* LIGHTNING_COMMON_PING_H */
|
||||||
|
@ -502,20 +502,13 @@ static void handle_ping(struct peer *peer, u8 *ping)
|
|||||||
|
|
||||||
static void handle_pong(struct peer *peer, const u8 *pong)
|
static void handle_pong(struct peer *peer, const u8 *pong)
|
||||||
{
|
{
|
||||||
u8 *ignored;
|
const char *err = got_pong(pong, &peer->local->num_pings_outstanding);
|
||||||
|
|
||||||
status_trace("Got pong!");
|
if (err) {
|
||||||
if (!fromwire_pong(pong, pong, &ignored)) {
|
peer_error(peer, "%s", err);
|
||||||
peer_error(peer, "Bad pong");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!peer->local->num_pings_outstanding) {
|
|
||||||
peer_error(peer, "Unexpected pong");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
peer->local->num_pings_outstanding--;
|
|
||||||
daemon_conn_send(&peer->daemon->master,
|
daemon_conn_send(&peer->daemon->master,
|
||||||
take(towire_gossip_ping_reply(pong, true,
|
take(towire_gossip_ping_reply(pong, true,
|
||||||
tal_len(pong))));
|
tal_len(pong))));
|
||||||
|
@ -1863,11 +1863,17 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
|
|
||||||
# Test gossip pinging.
|
# Test gossip pinging.
|
||||||
self.ping_tests(l1, l2)
|
self.ping_tests(l1, l2)
|
||||||
|
if DEVELOPER:
|
||||||
|
l1.daemon.wait_for_log('Got pong 1000 bytes \({}\.\.\.\)'
|
||||||
|
.format(l2.info['version']), timeout=1)
|
||||||
|
|
||||||
self.fund_channel(l1, l2, 10**5)
|
self.fund_channel(l1, l2, 10**5)
|
||||||
|
|
||||||
# channeld pinging
|
# channeld pinging
|
||||||
self.ping_tests(l1, l2)
|
self.ping_tests(l1, l2)
|
||||||
|
if DEVELOPER:
|
||||||
|
l1.daemon.wait_for_log('Got pong 1000 bytes \({}\.\.\.\)'
|
||||||
|
.format(l2.info['version']))
|
||||||
|
|
||||||
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
|
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
|
||||||
def test_routing_gossip_reconnect(self):
|
def test_routing_gossip_reconnect(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user