Commit Graph

44 Commits

Author SHA1 Message Date
Christian Decker a215cb47f1 gossip: Verify channel_update signatures 2017-04-11 16:56:27 -07:00
Christian Decker 58196b5a32 gossipd: Verify signatures for incoming channel_announcements 2017-04-11 16:56:27 -07:00
Christian Decker 6e81da3cd2 gossip: Fix a tag collision for different directions of a channel
Appending the channel direction ensures that the directions will be
treated independently. Without this only one direction would be
forwarded to the peers.
2017-03-29 12:51:15 +02:00
Christian Decker 7793bd1b9d gossip: Consolidated direction bit computation
The direction bit was computed in several spots and was inconsistent
in some cases. Now we compute it just in routing, and once when
starting up `channeld`, this avoids recomputing it all over the place.
2017-03-28 14:06:48 +10:30
Christian Decker 60a2227f0d channel: Disable channels that are lost via a channel_update
Before exiting, `channeld` constructs and sends a `channel_update`
marking the channel as disabled. This is the pro-active signalling
that the channel may no longer be used.
2017-03-23 13:34:03 +10:30
Christian Decker 73e65cac4d routing: Refactor get_route into its own method
The JSON-RPC call `getroute` and the functionality to compute the
actual route have been split so that we can reuse it independently of
the JSON-interface. Since this is now a routing-only method I also
moved it into `routing.[ch]` instead of `pay.c`.
2017-03-23 13:34:03 +10:30
Rusty Russell 7419fde9a0 Update to new spec: differentiate channel_id and short_channel_id.
The spec 4af8e1841151f0c6e8151979d6c89d11839b2f65 uses a 32-byte 'channel-id'
field, not to be confused with the 8-byte short ID used by gossip.  Rename
appropriately, and update to the new handshake protocol.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Christian Decker c15511cf39 routing: Actually return the port when parsing node_announcements
We parsed it, but did not pass it back out.
2017-02-18 13:09:08 +01:00
Christian Decker fb814a7a9e gossip: Adding announcement handling to the gossip subdaemon.
We now have all the pieces to wire in the handling functionality to
the new gossip subdaemon.
2017-02-03 05:52:11 +10:30
Christian Decker 9de880dce7 refactor: Move the gossip handlers to routing
Moving the common functionality out of p2p_announce, sharing it
between legacy and subdaemon architecture.
2017-02-03 05:52:11 +10:30
Christian Decker 92bc0abdc3 refactor: Move JSONRPC methods to separate compilation unit
This allows us to not care too much about bringing JSON into the new
subdaemons.
2017-02-03 05:52:11 +10:30
Christian Decker 76e2c980e1 gossip: Moving to intmap-based broadcast for the legacy daemon
Moved the broadcast functionality to broadcast.[ch]. So far this
includes only the enqueuing side of broadcasts, the dequeuing and
actual push to the peer is daemon dependent. This also adds the
broadcast_state to the routing_state and the last broadcast index to
the peer for the legacy daemon.
2017-02-03 05:52:11 +10:30
Christian Decker 3aa45a6d0b refactor: Moving write_ip and read_ip into routing.h
Further reduction in things in p2p_message so we can deprecate it
later.
2017-02-03 05:52:11 +10:30
Christian Decker 2a7e757053 refactor: Moving functionality out of p2p_announce
Further decoupling the old daemons from the new daemons.
2017-02-03 05:52:11 +10:30
Christian Decker 2c06524165 refactor: Moving legacy sync method out of routing
This was the only time we actually reference non-routing structs in
routing, so moving this out should allow us to get it working in the
new subdaemons.
2017-02-03 05:52:11 +10:30
Christian Decker 5d10093da3 refactor: Moving the node_map definition into routing.h
This allows us to move some legacy functions closer to where they are
actually used, and not worry about them when including routing.h into
the new subdaemons. `struct peer` is the main culprit here.
2017-02-03 05:52:11 +10:30
Christian Decker 3cb576d69d refactor: Moving gossip/routing specific state into its own struct
This used to be part of `lightningd_state` which is being split up for
the various subdaemons. The main change is the addition of the `struct
routing_state` in `routing.h` and the addition of `rstate` in `struct
lightningd_state` for backwards compatibility.
2017-02-03 05:52:11 +10:30
Rusty Russell 12b30ab4fc jsonrpc: register base on linkage.
Other than being neater (no more global list to edit!), this lets the
new daemon and old daemon have their own separate routines.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:08:15 +10:30
Christian Decker 570003235e gossip: Fixing minor issues
Thanks @rustyrussell for the review ^^
2017-01-03 15:08:05 +10:30
Christian Decker 0ed23c46a9 gossip: Implemented routing table sync with newly connected peers 2017-01-03 15:08:05 +10:30
Christian Decker e54c0adced gossip: Do not consider half-open connections for routes
Connections are in a half-open state after receiving the
`channel_announcement` and before the `channel_update` makes them
usable, so we need to ignore channels that are not yet fully open.
2017-01-03 15:08:05 +10:30
Christian Decker 57d5ae96a4 routing: Added channel_id and directions to connections
The gossip protocol spec refers to channels by their `channel_id` and
a direction. Furthermore, inbetween the `channel_announcement` and the
`channel_update` for either direction, the channel direction is in an
undefined state and cannot be used, so added the `half_add_connection`
function and an `active` flag to differentiate usable connections from
unusable ones.
2017-01-03 15:08:05 +10:30
Rusty Russell a4fdaab5b3 Use global secp256k1_ctx instead of passing it around.
If I'd known how large this patch would be (though trivial), I'd
have done it in parts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-02 18:12:58 +10:30
Rusty Russell 5adaf46b19 Merge remote-tracking branch 'origin/pr/65'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-05 13:48:16 +10:30
Rusty Russell b40c4ae766 json_getroute: don't leak.
Allocate the route off the current command, not dstate.  And in the
case where the route is somehow not via a peer, don't leak memory.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:04 +10:30
Rusty Russell fa402aac31 routing: fix hash of pubkeys.
Found by PVS Studio.

Reported-by: Jon Griffiths <jgriffiths@blockstream.io>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:33:06 +10:30
Christian Decker f9a4af62e3 irc: Added alias handling for node announcements
Aliases seem to be popular among users wanting to show off their node,
so let's add them :-)
2016-10-28 16:47:01 +02:00
Christian Decker a97d301155 routing: Refuse self-route
Fixes #50. Was causing a segfault because it was creating an empty route
and was trying to extract the first hop as next hop. Routes through self
can still be created manually, but `sendpay` would still refuse to act
on them due to the missing self-link.
2016-10-23 11:57:50 +02:00
Rusty Russell d47d19ef2b Merge remote-tracking branch 'origin/pr/44'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-17 12:31:19 +10:30
Christian Decker 594eb8109c jsonrpc: Added 'getnodes' to list known nodes.
getnodes returns an object containing a single array of 'nodes'. Each
element contains the node's ID, its hostname and its port. If
unknown (because we haven't seen a node announcement yet) then the port
is 0 and the hostname is null.
2016-10-02 14:52:24 +02:00
Christian Decker b2126375e0 irc: Add contact information to nodes
The routing table now includes hostnames and ports for the node as well
as a helper to add/update the nodes we learn about.
2016-10-02 14:30:25 +02:00
Christian Decker 8e2abfcc70 jsonrpc: Added 'getchannels' RPC method.
'getchannels' returns a 'channels' array containing an object for each
known channel. Each channel object represents one direction of a
bidirectional channel, with a from and a to node ID along with the fees
for that direction. This matched the internal storage of channels and
allows unbalanced fees for each direction.
2016-10-02 12:22:28 +02:00
Rusty Russell ea41386ed3 daemon: rename all the low-level commands to dev-
Rename the structs to match (and remove dev-echo).

This makes it clear that they're not the normal API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell ca80fc0286 getroute: add a risk factor.
We need some way to reflect the tradeoff between the possible delay if
a payment gets stuck, and the fees charged by nodes.  This adds a risk
factor which reflects the probability that a node goes down, and the
cost associated with losing access to our funds for a given time.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:48 +09:30
Rusty Russell 79b5663db7 routing: don't coredump on routes to neighbors.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 13:47:33 +09:30
Rusty Russell 7bebfe265c pay: remove route when a payment fails partway.
It's a bit harsh, but I'm assuming they'll get refreshed eventually.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:10:17 +09:30
Christian Decker 754616c45a routing: Fix for single hop routes segfaulting.
The first hop is being stripped from computed routes, however the
first channel of the route is being used to get our peer address. This
results in segfaults if the route is just one hop, i.e., has no first
channel to get the peer's address from. Fixed by simply using an
existing pointer to our peer.
2016-08-26 15:39:35 +09:30
Rusty Russell 830a65de46 daemon: --add-route option.
This allows hardcoded routes in the config file, which is required until
we get route advertisements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell 5f368f1c95 peer: save/load results in database.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell 87da9634bc routing: use ids, not nodes in interface.
Turns out to be more convenient.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell a613d8d1fb peer: make id a pointer, NULL until we know peer's ID.
Much better than undefined, and testing for NULL is better than
testing for STATE_INIT.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell f4f0c1aa18 daemon: add dev-routefail command.
We're about to change the code so that if it can't route, it will fail
the HTLC.  The current low-level tests will hate this, so have a dev switch
to turn that off.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell b1ac490bea daemon: add-route RPC command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 26a03acfd0 daemon: routing infrastructure.
Simple routing topology, and ability to ask about the cheapest route.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30