Rusty Russell
9449f387ac
daemon: primitive privkey handling.
Eventually this will be in a separate process, etc.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
29c8611e53
daemon: add helper to log hex.
Good for keys; eventually we'll want to log structures by type though.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
14cbcd467f
daemon: add global secp256k1 context for easy access.
This caches the tables, so you're not supposed to regenerate it all
the time.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
2df28021ac
daemon: command to connect
Now we can connect two daemons to each other. Who both say Hello! and
close.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
39120b3ac6
daemon: async DNS lookups.
Also based on pettycoin code.
(With embarrassing bug fixed where it didn't increment the address used,
thus using 100% CPU if that connect failed!)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
e4224f72d4
daemon: netaddr
Structure for a net address. We can expand it later to cover exotic
address types (Tor?).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
469401610f
daemon: socket code.
At the moment, if you connect it just says Hello! and closes the socket.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
c28a9ce6c7
daemon: lightning-cli
Minimal possible implementation; not real parsing or pretty printing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
9ccb51c93f
daemon: UNIX domain socket for JSON-based control.
Also taken from pettycoin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
6ccfcf4477
daemon: timeout structure for IO.
For better or worse, the ccan/timer structure is completely minimal,
and designed to be wrapped inside a container structure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
aed857a30c
json: routine to create a uint64_t field.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
725512fb03
json: parse bitcoind-style bitcoin amount.
Always of form d*.dddddddd; we turn that into satoshis, because we're
sane.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
06a25887da
json: routine to parse a uint64_t.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
ac4491909c
daemon/json: helpers for using jsmn.
Also taken from pettycoin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
0c81b0918a
daemon/jsmn: build the module.
Can't build inside the submodule, as that makes it dirty.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
378dadc371
daemon: configuration directory (default ~/.lightning).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
7b766f4bc8
daemon: fatal() function.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
89f1f1548e
daemon: dump logs on crash.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
117cf6b02d
daemon: add logging options.
Particularly logging to file.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
3e77c55a3b
Makefile: add daemon source sanity checks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
dd35260ce8
daemon: first code.
Logging code based heavily on pettycoin's.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
e1eef5db65
close_tx: don't use protobufs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
9aa0eac814
bitcoin: hand in a secp256k1_context to all routines.
We don't want to re-create them internally, ever.
The test-cli tools are patched to generate them all the time, but
they're not performance critical.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
cc1b1d7de7
funding: adjust_fee() to allow fee alterations.
This is used for figuring out the close transaction balances,
but can also be used in the future for dynamic fee support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
d5c30ee30b
funding: funding_find_htlc and funding_remove_htlc.
Helpers for daemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
6d6abd57e7
funding: remove protobufs.
Use our own structure with the information we need about HTLCs,
and remove protobufs from the API.
The is_funder() helper goes inside gather_updates.h.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
d95d8a99c2
create_commit_tx: don't use protobufs in the API.
Hand anchor details and pubkeys directly; this is what we want
for the actual daemon which doesn't keep raw packets around.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
65cc6bbd50
pkt_err: make it variadic.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
3374ddd2a6
bitcoin: use a length arg to bitcoin_tx_from_hex
Our json parser doesn't use nul-terminated strings.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
cf547d491b
bitcoin: add len arg to pubkey conversion function.
Our json parser doesn't give nul-terminated strings.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
79e1c9bb62
state: make bitcoin_commit() take a non-const peer.
We have to sign the commit at this stage, so easiest if peer isn't const
so we can sign it in-place.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
6a7a046f60
state: add peer_unwatch_close_timeout() call.
This tell us to disarm the INPUT_CLOSE_COMPLETE_TIMEOUT: either we hit
an error and are going to unilateral close, or we received their signature
successfully.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
144ab3bef4
state: make tx arguments const.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
ebf2bc57d8
state: add async anchor creation.
Actually generating the anchor transaction in my implementation
requires interaction with bitcoind, which we want to be async. So add
a callback and a new state to wait for it.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
0db3c03ed1
state: fix BITCOIN_HTLC_TOTHEM_SPENT idata.
We use both union fields idata->btc and idata->htlc, which is clearly
wrong. Have peer_tx_revealed_r_value return the HTLC it's talking
about.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
2b3d5b4049
state: remove all traces of struct state_effect.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
63ea6bfd7a
state: add callbacks for adding/removing watches.
This lets us eliminate struct state_effect altogether (the next patch
removes the now-unused arguments).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
1a20e8094f
state: return tx to be queued directly.
Instead of effect->broadcast_tx.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
e984df486d
state: return Pkt to be queued directly.
Instead of effect->send_pkt.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
7383da5f87
state: remove update_theirsig effect.
They get this from accept_pkt_update_accept() or accept_pkt_update_signature().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
63cb0667f6
state: use callbacks for htlc management.
We only have one htlc in flight at a time, but sometimes it changes:
particularly when we are lowpriority and a highpriority request comes
in. Handle this using a set of callbacks for htlc handling.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
c1dc7137ba
names: generate names for command_status and state_peercond.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
f48adb097e
state: use peer_unexpected_pkt() for an unexpected packet.
Instead of effect->in_error.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
4d9041e62a
state: fix case where we replied to an error with an error.
Found by fixing bogus test in test_state_coverage.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
9013a7d872
state: set peer->state directly.
Instead of new_state effect.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
4c9a9f8982
state: return status of current command.
We temporarily move effect to the end of the arg list: we'll get rid
of it eventually.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
03268014b4
state: use PEER_BUSY when doing a command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
14ede84d87
state: set peercond in peer directly.
Instead of stop_packets or stop_commands effects.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
50a4b14a9a
test/test_state_coverage.c: remove deferred packet handling.
We no longer defer packets.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
Rusty Russell
3ab4ba1e6f
state: add _THEYCOMPLETED states to reflect receiving PKT_OPEN_COMPLETE
This is cleaner than deferring the packet receive and asking for it later.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago