lightningd/peer_control: don't create peer struct until we've connected.

We currently create a peer struct, then complete handshake to find out
who it is.  This means we have a half-formed peer, and worse: if it's
a reconnect we get two peers the same.

Add an explicit 'struct connection' for the handshake phase, and
construct a 'struct peer' once that's done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-05-22 20:56:49 +09:30
parent 61a2ed97e1
commit f6495d3310
8 changed files with 256 additions and 195 deletions

View File

@@ -112,17 +112,6 @@ static void peer_ready(struct subd *gossip, const u8 *msg)
type_to_string(msg, struct pubkey, peer->id),
unique_id);
if (peer->connect_cmd) {
struct json_result *response;
response = new_json_result(peer->connect_cmd);
json_object_start(response, NULL);
json_add_pubkey(response, "id", peer->id);
json_object_end(response);
command_success(peer->connect_cmd, response);
peer->connect_cmd = NULL;
}
peer_set_condition(peer, GOSSIPING);
}