| 164 | } |
| 165 | |
| 166 | static struct io_plan *handshake_success(struct io_conn *conn, |
| 167 | const struct pubkey *them, |
| 168 | const struct wireaddr_internal *addr, |
| 169 | struct crypto_state *cs, |
| 170 | struct oneshot *timer, |
| 171 | char **args) |
| 172 | { |
| 173 | int peer_fd = io_conn_fd(conn); |
| 174 | struct pollfd pollfd[2]; |
| 175 | |
| 176 | if (initial_sync) |
| 177 | set_feature_bit(&features, |
| 178 | OPTIONAL_FEATURE(OPT_INITIAL_ROUTING_SYNC)); |
| 179 | |
| 180 | if (!no_init) { |
| 181 | u8 *msg; |
| 182 | struct tlv_init_tlvs *tlvs = NULL; |
| 183 | if (explicit_network) { |
| 184 | tlvs = tlv_init_tlvs_new(NULL); |
| 185 | tlvs->networks = tal_arr(tlvs, struct bitcoin_blkid, 1); |
| 186 | tlvs->networks[0] = chainparams->genesis_blockhash; |
| 187 | } |
| 188 | msg = towire_init(NULL, NULL, features, tlvs); |
| 189 | |
| 190 | sync_crypto_write(peer_fd, cs, take(msg)); |
| 191 | /* Ignore their init message. */ |
| 192 | tal_free(sync_crypto_read(NULL, peer_fd, cs)); |
| 193 | tal_free(tlvs); |
| 194 | } |
| 195 | |
| 196 | if (stream_stdin) |
| 197 | pollfd[0].fd = STDIN_FILENO; |
| 198 | else |
| 199 | pollfd[0].fd = -1; |
| 200 | pollfd[0].events = POLLIN; |
| 201 | pollfd[1].fd = peer_fd; |
| 202 | pollfd[1].events = POLLIN; |
| 203 | |
| 204 | while (*args) { |
| 205 | u8 *m = tal_hexdata(NULL, *args, strlen(*args)); |
| 206 | if (!m) |
| 207 | errx(1, "Invalid hexdata '%s'", *args); |
| 208 | sync_crypto_write(peer_fd, cs, take(m)); |
| 209 | args++; |
| 210 | } |
| 211 | |
| 212 | while (max_messages != 0 || pollfd[0].fd != -1) { |
| 213 | beint16_t belen; |
| 214 | u8 *msg; |
| 215 | |
| 216 | if (poll(pollfd, ARRAY_SIZE(pollfd), |
| 217 | timeout_after < 0 ? -1 : timeout_after * 1000) == 0) |
| 218 | return 0; |
| 219 | |
| 220 | /* We always to stdin first if we can */ |
| 221 | if (pollfd[0].revents & POLLIN) { |
| 222 | if (!read_all(STDIN_FILENO, &belen, sizeof(belen))) |
| 223 | pollfd[0].fd = -1; |
nothing calls this directly
no test coverage detected