A connect handler that gets called when a connection to another node * gets established. */
| 2321 | * gets established. |
| 2322 | */ |
| 2323 | void clusterLinkConnectHandler(connection *conn) { |
| 2324 | clusterLink *link = (clusterLink*)connGetPrivateData(conn); |
| 2325 | clusterNode *node = link->node; |
| 2326 | if (node == nullptr) |
| 2327 | return; // we're about to be freed |
| 2328 | |
| 2329 | /* Check if connection succeeded */ |
| 2330 | if (connGetState(conn) != CONN_STATE_CONNECTED) { |
| 2331 | serverLog(LL_VERBOSE, "Connection with Node %.40s at %s:%d failed: %s", |
| 2332 | node->name, node->ip, node->cport, |
| 2333 | connGetLastError(conn)); |
| 2334 | freeClusterLink(link); |
| 2335 | return; |
| 2336 | } |
| 2337 | |
| 2338 | /* Register a read handler from now on */ |
| 2339 | connSetReadHandler(conn, clusterReadHandler); |
| 2340 | |
| 2341 | /* Queue a PING in the new connection ASAP: this is crucial |
| 2342 | * to avoid false positives in failure detection. |
| 2343 | * |
| 2344 | * If the node is flagged as MEET, we send a MEET message instead |
| 2345 | * of a PING one, to force the receiver to add us in its node |
| 2346 | * table. */ |
| 2347 | mstime_t old_ping_sent = node->ping_sent; |
| 2348 | clusterSendPing(link, node->flags & CLUSTER_NODE_MEET ? |
| 2349 | CLUSTERMSG_TYPE_MEET : CLUSTERMSG_TYPE_PING); |
| 2350 | if (old_ping_sent) { |
| 2351 | /* If there was an active ping before the link was |
| 2352 | * disconnected, we want to restore the ping time, otherwise |
| 2353 | * replaced by the clusterSendPing() call. */ |
| 2354 | node->ping_sent = old_ping_sent; |
| 2355 | } |
| 2356 | /* We can clear the flag after the first packet is sent. |
| 2357 | * If we'll never receive a PONG, we'll never send new packets |
| 2358 | * to this node. Instead after the PONG is received and we |
| 2359 | * are no longer in meet/handshake status, we want to send |
| 2360 | * normal PING packets. */ |
| 2361 | node->flags &= ~CLUSTER_NODE_MEET; |
| 2362 | |
| 2363 | serverLog(LL_DEBUG,"Connecting with Node %.40s at %s:%d", |
| 2364 | node->name, node->ip, node->cport); |
| 2365 | } |
| 2366 | |
| 2367 | /* Read data. Try to read the first field of the header first to check the |
| 2368 | * full length of the packet. When a whole packet is in memory this function |
nothing calls this directly
no test coverage detected