| 186 | #endif |
| 187 | |
| 188 | struct io_plan *peer_exchange_initmsg(struct io_conn *conn, |
| 189 | struct daemon *daemon, |
| 190 | const struct feature_set *our_features, |
| 191 | const struct crypto_state *cs, |
| 192 | const struct node_id *id, |
| 193 | const struct wireaddr_internal *addr, |
| 194 | struct oneshot *timeout, |
| 195 | bool incoming) |
| 196 | { |
| 197 | /* If conn is closed, forget peer */ |
| 198 | struct early_peer *peer = tal(conn, struct early_peer); |
| 199 | struct io_plan *(*next)(struct io_conn *, struct early_peer *); |
| 200 | struct tlv_init_tlvs *tlvs; |
| 201 | |
| 202 | peer->daemon = daemon; |
| 203 | peer->id = *id; |
| 204 | peer->addr = *addr; |
| 205 | peer->cs = *cs; |
| 206 | peer->incoming = incoming; |
| 207 | |
| 208 | /* Attach timer to early peer, so it gets freed with it. */ |
| 209 | notleak(tal_steal(peer, timeout)); |
| 210 | |
| 211 | /* BOLT #1: |
| 212 | * |
| 213 | * The sending node: |
| 214 | * - MUST send `init` as the first Lightning message for any |
| 215 | * connection. |
| 216 | * ... |
| 217 | * - SHOULD set `networks` to all chains it will gossip or open |
| 218 | * channels for. |
| 219 | */ |
| 220 | tlvs = tlv_init_tlvs_new(tmpctx); |
| 221 | tlvs->networks = tal_dup_arr(tlvs, struct bitcoin_blkid, |
| 222 | &chainparams->genesis_blockhash, 1, 0); |
| 223 | |
| 224 | /* set optional tlv `remote_addr` on incoming IP connections */ |
| 225 | tlvs->remote_addr = NULL; |
| 226 | |
| 227 | /* BOLT #1: |
| 228 | * The sending node: |
| 229 | * ... |
| 230 | * - SHOULD set `remote_addr` to reflect the remote IP address (and port) of an |
| 231 | * incoming connection, if the node is the receiver and the connection was done |
| 232 | * via IP. |
| 233 | */ |
| 234 | if (incoming && addr->itype == ADDR_INTERNAL_WIREADDR && |
| 235 | address_routable(&addr->u.wireaddr, true)) { |
| 236 | switch (addr->u.wireaddr.type) { |
| 237 | case ADDR_TYPE_IPV4: |
| 238 | case ADDR_TYPE_IPV6: |
| 239 | tlvs->remote_addr = tal_arr(tlvs, u8, 0); |
| 240 | towire_wireaddr(&tlvs->remote_addr, &addr->u.wireaddr); |
| 241 | break; |
| 242 | /* Only report IP addresses back for now */ |
| 243 | case ADDR_TYPE_TOR_V2_REMOVED: |
| 244 | case ADDR_TYPE_TOR_V3: |
| 245 | case ADDR_TYPE_DNS: |
no test coverage detected