1.3.2 Connecting and Disconnecting

When establishing the first connection to a graph, it is necessary for an application to supply the Peer-to-Peer Graphing Protocol with the address and port of an active node. The Peer-to-Peer Graphing Protocol does not define any discovery mechanism for discovering nodes for the initial connection.

When the address and port of an existing node are found, the node first authenticates with the existing node. After successful authentication, the existing node will either allow the connection or refuse it. In either case, the existing node will provide the connecting node with a list of its neighbors. If the existing node refused the connection (usually because it already has the maximum number of neighbors), the connecting node will attempt to connect to one of the existing node's neighbors.

To participate in a graph, a node begins listening for connection requests from other nodes.

  • If the node is the creator of the graph, it begins listening immediately.

  • If another node is found and a connection is established, the local node begins listening after synchronization.

  • If a connection cannot be established and the node has previously synchronized its database, it begins listening.

  • If a connection cannot be established and the node has never synchronized its database, it does not listen - it cannot be part of the graph until it first finds another node.

After the node has synchronized and started listening, it attempts to connect to more nodes in the graph. There are several ways to find other nodes:

  • Through available presence records in the graph.

  • Through available contact records in the graph.

  • Through node information passed back from neighbors in the graph.

After a node is found, the same mechanism is used to create additional connections. For more information, see section 3.1.7.24.

When a node disconnects from a neighbor, either because it is leaving the graph or because it has pruned the connection as part of graph maintenance, it first sends a message to the neighbor. The message contains the reason for disconnecting and provides a list of the disconnecting node's neighbors. For more information, see section 3.1.7.25.