PIMP

Peer Instant Messenger Protocol

Users:

 

Developers:

Developer Home
Requirements

Protocol Specification

Version 0.1

 

Overview

Each node on the PIMP network will have a 128 bit routing key, which is similar to an IP address on the Internet.  Since the protocol will use a public/private key cryptography scheme, each user's public key will be used as the routing key, which should ensure that there are no collisions.  No user may have key 0x00000000000000000000000000000000, because this key is reserved as the broadcast address.  Messages addressed to the broadcast address should be routed to every node on the network.

Each node will maintain several active connections.  The exact number is not specified by the protocol, and should ideally be configurable by the user.  Normal user nodes probably will typically maintain between 5 and 15 active connections.  Nodes serving primarily as routers will maintain many more active connections.

The network is based on passing messages back and forth.  It is important to note that these messages are not necesarily the actual instant messages sent by users, but rather the equivalent of packets in TCP/IP.  Each message type has slightly different routing procedures, but all follow a typical pattern.  When a node receives a message, it first checks to see if message has reached its proper desination.  If so, the node processes the message accordingly.  Otherwise, the node checks its active connections and forwards the packet on to the node connected to this node whose routing key is "closest" to the destination of the message.  In the case of a message addressed to the broadcast key, the node should both process the node, and then forward the message out all of its active connections.  In each messag header there is a Global Unique Identifier (GUID) and a number indicating the message's Time To Live (TTL).  Each node maintains a list of recently seen GUID's.  When a node receives a message, it should drop the message if either the GUID has been seen before or the TTL is zero.  When forwarding the message, TTL should be decremented by one.  There is a possibility that the randomly generated GUID's will be repeated, but this should be a rare enough occurence to not disrupt the network too badly.

Messages

All mesages are made up of a message header describing key details about the message, and a message payload which varies based on type of message this is.  More detail is given below.

If a node encounters a message of a type it does not recognize, it should simply forward the entire message on toward its destination.  This allows the protocol to support new types of messages without needing all nodes to support them.

Header

Bytes Field Name Description
0 - 15 GUID A string of 16 hex digits describing the message's Global Unique Identifier.
16 - 17 Message Type 2 hex digits describing the numerical ID of the Message Type.  See below for more
18 - 19 TTL 2 hex digits describing the message's remaining Time to Live.
20 - 51 Destination Address 32 hex digits describing the message's destination routing key.
52 - 83 Source Address 32 hex digits describing the routing key of the node that originated the message.
84 - 87 Payload Size 4 hex digits describing the size of the message's payload in bytes.  The current protocol only supports message payloads of 64K or less.

Total Message Header Size:  88 bytes.

Types

0x00 - ANNOUNCE
Payload:
ProtocolID - null-terminated string of bytes describing the protocol.  ex: "tcp"
Address - null-terminated string of bytes describing all information needed to connect to this node over the givern protocol.  For the TCP/IP protocol this could be and IP address and port, such as "192.168.0.1:7296", or a domain name and port, "pimpnode.mydomain.com:7296".
Description:
This message is used to give other nodes the information needed to establish a direct connection with this node.  All nodes that come in contact with this message may look at the contents and optionally update their routing tables.  This message is routed otherwise normally.
0x01 - ANNOUNCE_REQUEST
Payload:
none.
Description:
The destination of this message should respond with an ANNOUNCE.  This message is primarily used to establish shorter paths to a given node.
0x02 - PING
Payload:
Hops - 2 hex digits describing the number of nodes this message has visited thus far.
Description:
What good would a network be without ping?  This, in combination with PONG, allows nodes to determine their distance from a certain node, and also to determine latency and other network statistics.

Route this message normally, except increment Hops by 1 before forwarding it.

0x03 - PONG
Payload:
toHops - 2 hex digits describing the number of nodes the PING that caused this message visited on the way to its destination.
fromHops - 2 hex digits describing the number of nodes this message
Description:
This message is a response to PING.  It carries both the number of Hops to and from the node, since this number may be different.  Route like PING, incrementing fromHops at each node.
0x04 - MESSAGE
Payload:
Message - null terminated string containing the encrypted IM that the user sent to the given user.
Description:
This message passes actual instant messages through the network.  Route normally.
0x05 - QUERY
Payload:
A set of query strings.  The exact number is not known, so the node should continue reading until it has read the Payload Size number of bytes.  Query strings have this form:
"field=value"
Description:
This allows nodes to find new people to chat with based on certain directory info, such as name, age, location, language, etc.  This will almost always be addressed to the broadcast key.  If the destination node meets the criteria, it should respond with an ANNOUNCE, and optionally a DIRECTORY_INFO.  This message is routed normally.
0x06 - DIRECTORY_REQUEST
Payload:
none.
Description:
This allows a node to retrieve directory info about another connected user.  It is routed normally, and the destination should respond with a DIRECTORY_INFO message, although it may choose not too depending on the user's privacy settings.
0x07 - DIRECTORY_INFO
Payload:
A set of info strings in the same form as the query strings from QUERY.
Description:
Normal Routing.  This message contains directory info such as phone number, age, name, language, etc.
0x08 - STATUS_REQUEST
Payload:
none
Description:
Route this normally.  The destination should respond with a STATUS.
0x09 - STATUS
Payload:
A string describing the user's current status (away, online, out to lunch, etc.). 
Description:
Normal routing.  This message is a response to STATUS_REQUEST.

Cryptography

The cryptography system has not been developed in detail yet.  All that is known is that the protocol will almost definitely use a public/private key system, and probably attach hashes of messages to form digital signatures.