A connect handler that gets called when a connection to another node * gets established. */
| 2273 | * gets established. |
| 2274 | */ |
| 2275 | void clusterLinkConnectHandler(connection *conn) { |
| 2276 | clusterLink *link = connGetPrivateData(conn); |
| 2277 | clusterNode *node = link->node; |
| 2278 | |
| 2279 | /* Check if connection succeeded */ |
| 2280 | if (connGetState(conn) != CONN_STATE_CONNECTED) { |
| 2281 | serverLog(LL_VERBOSE, "Connection with Node %.40s at %s:%d failed: %s", |
| 2282 | node->name, node->ip, node->cport, |
| 2283 | connGetLastError(conn)); |
| 2284 | freeClusterLink(link); |
| 2285 | return; |
| 2286 | } |
| 2287 | |
| 2288 | /* Register a read handler from now on */ |
| 2289 | connSetReadHandler(conn, clusterReadHandler); |
| 2290 | |
| 2291 | /* Queue a PING in the new connection ASAP: this is crucial |
| 2292 | * to avoid false positives in failure detection. |
| 2293 | * |
| 2294 | * If the node is flagged as MEET, we send a MEET message instead |
| 2295 | * of a PING one, to force the receiver to add us in its node |
| 2296 | * table. */ |
| 2297 | mstime_t old_ping_sent = node->ping_sent; |
| 2298 | clusterSendPing(link, node->flags & CLUSTER_NODE_MEET ? |
| 2299 | CLUSTERMSG_TYPE_MEET : CLUSTERMSG_TYPE_PING); |
| 2300 | if (old_ping_sent) { |
| 2301 | /* If there was an active ping before the link was |
| 2302 | * disconnected, we want to restore the ping time, otherwise |
| 2303 | * replaced by the clusterSendPing() call. */ |
| 2304 | node->ping_sent = old_ping_sent; |
| 2305 | } |
| 2306 | /* We can clear the flag after the first packet is sent. |
| 2307 | * If we'll never receive a PONG, we'll never send new packets |
| 2308 | * to this node. Instead after the PONG is received and we |
| 2309 | * are no longer in meet/handshake status, we want to send |
| 2310 | * normal PING packets. */ |
| 2311 | node->flags &= ~CLUSTER_NODE_MEET; |
| 2312 | |
| 2313 | serverLog(LL_DEBUG,"Connecting with Node %.40s at %s:%d", |
| 2314 | node->name, node->ip, node->cport); |
| 2315 | } |
| 2316 | |
| 2317 | /* Read data. Try to read the first field of the header first to check the |
| 2318 | * full length of the packet. When a whole packet is in memory this function |
nothing calls this directly
no test coverage detected