| 203 | } |
| 204 | |
| 205 | struct io_plan *peer_exchange_initmsg(struct io_conn *conn, |
| 206 | struct daemon *daemon, |
| 207 | const struct feature_set *our_features, |
| 208 | const struct crypto_state *cs, |
| 209 | const struct node_id *id, |
| 210 | const struct wireaddr_internal *addr, |
| 211 | struct oneshot *timeout, |
| 212 | enum is_websocket is_websocket, |
| 213 | struct timemono starttime, |
| 214 | bool incoming) |
| 215 | { |
| 216 | /* If conn is closed, forget peer */ |
| 217 | struct early_peer *peer = tal(conn, struct early_peer); |
| 218 | struct io_plan *(*next)(struct io_conn *, struct early_peer *); |
| 219 | struct tlv_init_tlvs *tlvs; |
| 220 | |
| 221 | peer->daemon = daemon; |
| 222 | peer->id = *id; |
| 223 | peer->addr = *addr; |
| 224 | peer->cs = *cs; |
| 225 | peer->incoming = incoming; |
| 226 | peer->is_websocket = is_websocket; |
| 227 | peer->timeout = timeout; |
| 228 | peer->starttime = starttime; |
| 229 | |
| 230 | /* BOLT #1: |
| 231 | * |
| 232 | * The sending node: |
| 233 | * - MUST send `init` as the first Lightning message for any |
| 234 | * connection. |
| 235 | * ... |
| 236 | * - SHOULD set `networks` to all chains it will gossip or open |
| 237 | * channels for. |
| 238 | */ |
| 239 | tlvs = tlv_init_tlvs_new(tmpctx); |
| 240 | tlvs->networks = tal_dup_arr(tlvs, struct bitcoin_blkid, |
| 241 | &chainparams->genesis_blockhash, 1, 0); |
| 242 | |
| 243 | /* set optional tlv `remote_addr` on incoming IP connections */ |
| 244 | tlvs->remote_addr = NULL; |
| 245 | |
| 246 | /* BOLT #1: |
| 247 | * The sending node: |
| 248 | * ... |
| 249 | * - SHOULD set `remote_addr` to reflect the remote IP address (and port) of an |
| 250 | * incoming connection, if the node is the receiver and the connection was done |
| 251 | * via IP. |
| 252 | */ |
| 253 | if (incoming |
| 254 | && addr->itype == ADDR_INTERNAL_WIREADDR |
| 255 | && !addr->u.wireaddr.is_websocket |
| 256 | && address_routable(&addr->u.wireaddr.wireaddr, true)) { |
| 257 | switch (addr->u.wireaddr.wireaddr.type) { |
| 258 | case ADDR_TYPE_IPV4: |
| 259 | case ADDR_TYPE_IPV6: |
| 260 | tlvs->remote_addr = tal_arr(tlvs, u8, 0); |
| 261 | towire_wireaddr(&tlvs->remote_addr, &addr->u.wireaddr.wireaddr); |
| 262 | break; |
no test coverage detected