P10 Protocol

This document is based on Undernet's P10 protocol specification, as of ircu2.10.12. It aims to be a practical guide for implementing and maintaining the protocol, with DareNET's extensions, not just as a reference manual; therefore, it can be considered a "work in progress," continually being updated.

Concepts
The P10 protocol uses a scheme of "Numerics" to uniquely identify a server or client within the network. Each server has its own unique numeric (0 -> 4095), and each client has its own numeric within that server (0 -> 262,143).

The numerics are encoded into a Base64 stream to maintain human readable data flow and reduce the size of the messages. The Base64 character set used by the P10 protocol is included below, this defines all valid characters allowed in a Base64 numeric with "A" representing 0 and "]" representing 63.

Server numerics consist of two (2) characters, with the minimum, 0, being represented by "AA", and the maximum, 4095, being represented by "]]". Client numerics are three (3) characters long, with the minimum, 0, being represented by "AAA", and the maximum, 262,143, being represented by "]]]".

The unique identifier of a client on the network, referred to as a numnick, is five (5) characters long and consists of a combination of both the server and client numeric in the format SSCCC.

As an example, consider a server "irc.darenet.org" which has a numeric of 2, translating to "AC" in Base64. On this server exists a client, which has been allocated the numeric 63, translating to "AA]" in Base64. Therefore, the numnick of this client on the network is "ACAA]". From this, we can determine which server the message came from, as well as the client who sent it.

These numerics are used to prefix every message issued on the stream except for the initial  or   message, which are not prefixed. Therefore, every message that can be received from a server will consist of the format:

For example:

Command Token Table
The below table lists all acceptable messages, along with their relevant "token", which is used in server<>server communication. The aim of tokenization is to reduce the bandwidth used during network communication by reducing the total length of common message identifiers.

Server Registration and Authentication
After a TCP has been established, the server initially introduces itself via a  message, as follows:

password is simply a plain text password that is compared with the password present in the destination servers configuration file, and is used to confirm credentials after the  message has been received, as follows:

For example

1     2               3 4         5         6   7     8 9 SERVER irc.darenet.org 1 933022556 947908144 J10 AA]]] + :[127.0.0.1] A DareNET Client Server.


 * 1) The   message indicates this connection wishes to introduce a new server to the network.
 * 2) The name of the server being introduced.
 * 3) The hop count of the server being introduced; this is always 1 if you are introducing yourself.
 * 4) The epoch timestamp specifying when the ircd was started.
 * 5) The epoch timestamp specifying when the server initiated the link to the network.
 * 6) The protocol identifier of the server being introduced.
 * 7) This identifier informs the network which protocol it is compliant with. If it is P10 compliant, the value for this parameter will be "P10".
 * 8) If the server being introduced has not yet successfully synced its database with the network (i.e., completed its net.burst), then the value should be prefixed with a "J" instead of a "P" (e.g., J10) to indicate it is currently still joining the network.
 * 9) The protocol should always be prefixed with a J (e.g., JXX) when the server is introducing itself.
 * 10) The numeric, and maximum connections identifier for this server.
 * 11) This numeric is formatted exactly the same as a numnick. The first two (2) characters identify the server's numeric, whilst in this situation, the final three (3) characters define the maximum number of clients that this server can hold (and more importantly, the maximum number of numerics it will generate). This is always one less than power of two, because the server uses this as a bitmask. A server can give out a higher numeric than this; however, it will be ANDed with this number to find its entry slot. The reason for this is so a server, which is near the maximum number of clients, can give out more numerics than it's using to prevent a new client getting a numeric that was used only seconds ago, and possibly get messages destined to the old user.
 * 12) The example "AA]]]" shows that this is a server with numeric 0, which will generate client numerics up to 262,143.
 * 13) Possibly one or more flags indicating the type of server this is.
 * 14) Allowed values: + (normal server), +h (hub, hidden in /map), +s (services). It may also be "0" for implementations which do not support the flags parameter.
 * 15) The final parameter simply consists of a textual description of the server prefixed by a colon. This is displayed in a client's   line, as well as in the   reply. By convention, if this is a leaf server, it contains the server's IP in square brackets at the beginning of the string.

Network Database Resynchronization
As discussed above, the connection is established by sending a  message, and a   message. One may send  messages, and one must reply with the proper   messages (in long/"non P10" format). One must not send anything else in this stage. One may ignore other messages on the receiving end, such as any status notices.

Once the connection (server link) has been established and verified, the next step is to synchronize various databases between the two servers. A net burst is sent to tell the other end of the link about the complete network state. The server which initiated the connection should wait until it has received the  message from the accepting server, before it sends the net burst.

The messages that form the net burst must be generated in an order which allows the receiving server to create the objects and relationships represented by each message, at the moment the message is received. So, first server objects must be created and then the client objects connected to that server, and so on. Likewise, a server that is connected closer must be created first before a server behind it can be introduced, etc.

Because servers may be rejected as function of which servers are introduced, it makes most sense to first introduce all servers before introducing clients. This in order to avoid processing parts of a net burst, creating client objects, which need to be destructed a second later again.

Therefore, the net burst is constructed as follows:

Servers
Server details are transmitted via  messages, similar to the initial introduction message, with the following format:

The syntax of this message is nearly identical to the originally received server message, with the exception being that the message is prefixed (i.e.,  message is sent for all servers on the network. Before a   message for a given server is sent, a   message for any server in front of that server must have already been sent. This can be implemented by first sending   messages for all servers with hop count 1, then for all servers with hop count 2, and so on.

Glines
Any currently unexpired global Glines are transmitted via  messages along with lastmod TS.

Zlines
Any currently unexpired global Zlines are transmitted via  messages along with lastmod TS.

Shuns
Any currently unexpired global Shuns are transmitted via  messages along with lastmod TS.

Jupes
Any currently unexpired JUPEs are transmitted via  messages with the following format:

For example:

1 2  3 4                  5         6         7 AZ JU * +juped.darenet.org 000003593 955419707 :Juped Server

Notes:


 * 1) '''  message token.
 * 2) The target that should apply this JUPE (always "*" during bursts).
 * 3) <server_name - The name of the server to JUPE, prefixed with a "+" if the JUPE is active, or with a "-" if its not.
 * 4)   - The remaining absolute lifetime of the JUPE, expressed in seconds.
 * 5)   - An epoc timestamp of the last time the JUPE was modified.
 * 6)   - The reason the JUPE was applied.

Welcomes
Any global Welcomes are transmitted via  messages along with lastmod TS.

Clients
Information on all clients/users is transmitted via  messages, of the following format:

For example:

1 2 3       4 5         6    7            8     9      10    11 AF N Client1 1 947957573 User userhost.net +oiwg DAqAoB AFAAA :Generic Client.

Notes:


 * 1) '''  message token.
 * 2)   - The nickname of this client, currently max 30 characters.
 * 3)  - The hop count of this client (i.e., how many servers away it is on).
 * 4)   - An epoch timestamp indicating when the user was created.
 * 5)   - The "user" part of the user@host mask.
 * 6)   - The "host" part of the user@host mask.
 * 7) [OPTIONAL] <+modes> - User modes. If present, this is always "+. The special +r usermode is followed by the client's account name; see documentation for.
 * 8)  - The real IP address of this client, a base64 encoded 32bit int.
 * 9)   - The client's numeric (numnick), in SSCCC format.
 * 10)   - Free form user info line.

Channels
Channel details and membership information is synchronized through one (or more)  messages for each channel that exists, which are formatted as follows:

For example: 1 2 3        4         5      6   7  8                                         9         AZ B #darenet 949217470 +tinkl key 56 AAAAA,AAAAB,AAAAC,ABAAA,ABAAB,ABAAC,ACAAA :%*!*@*.net ~ *!*@*.com

Notes:


 * 1) '''  command token.
 * 2)   - The name of the channel to which this data belongs to. Currently #Channel and +Channel names can be sent in a   message; however, &Channels are not, since by definition they are local to the server.
 * 3)  An epoch timestamp indicating when the channel was created.
 * 4) [OPTIONAL] [+modes] - Channel modes.
 * 5) The channel may have a number of modes set. as well as relevant mode arguments in the following 2 parameters.
 * 6) [OPTIONAL] [arg1] - Channel key, this parameter is present if the channel modes contain a "k" mode.
 * 7) [OPTIONAL] [arg2] - Channel limit, this parameter is present if the channel modes contain a "l" mode.
 * 8)  - A comma separated list of client numerics, with the following specific formatting rules to indicate +o, +h, +v and +ohv channel members.
 * 9) Numerics can have the following symbols appended on then: ":ohv", ":oh", ":ov", ":hv", ":v", ":h" or ":o". These indicate that this numeric is either opped (:o), halfoped, (:h), voiced (:v) or a combination of the three. This state applies to the numeric it is attached to, and all subsequent numerics until another state is encountered. For example: AAABA:ov,AAABB:o,AAABC,AAABD,AAABE:v,AAABZ. In this example, AAABA is both opped and voiced; AAABB, AAABC and AAABD are opped leaving AAABE and AAABZ voiced.
 * 10) The first numeric of the member list will always contain a state symbol.
 * 11) [OPTIONAL] [:%bans [~ excepts]] - A space separated list of bans and/or excepts present in the channel. The start of the ban stream is indicated by a ":%', with everything following being the ban list, up until a single "~", which indicates the start of an except stream, with everything following being the except list.
 * 12) For example: " " which would add the following bans to the channel "*!*@*.foobar.net and another!ban@*.com, and the following except *!*fred@a.host.co.uk.

If the length of a  message exceeds the maximum length of a line (512 characters), then the remaining channel members/bans/excepts are sent in subsequent   messages. The subsequent  messages are only used to add additional members to the channel, and if necessary, channel bans and excepts. There will be no "mode" parameters presents. A sample additional  message is shown below:

AZ B #darenet 949217470 ACAAB:o,ACAAD :%*!*another@*.ban.com

Nick collisions
Each received  message with a server as source introduces a new client, while each   message with a client as source changes the name of a given client. The name (i.e., nickname) of a client must be unique on the network. Nick collisions are a result of an incoming  message, when an existing user already has the nick.

If the collision is with a local client which has yet to fully register with the server (i.e., has yet to be broadcasted to the other servers), then this local client is removed.

Otherwise:


 * Both users are killed if their TS (last nick change) is equal, or
 * the user with the higher TS is killed if the user@host differs, or
 * the user with the lower TS is killed if the user@host are equal.

Since the target of the  message is the numeric, it is safe to send them in any needed direction; no risk of killing the wrong user. If the collision is with a local client, also send a  upstream (this for security reasons and might not really be necessary).

Local channels
Local channel names (those starting with an ampersand, "&") are "disallowed" in the P10 protocol, being a server<>server protocol. One must take care to not send any messages about local channels to other servers, and to not accept them when parsing messages.

Summary
The following table summarizes the sequence of events that occur when a server connects (links) to another server. S1 is our server, while S2 is a HUB on the target network.

Example Session: [WRITE]: PASS :54321 [WRITE]: SERVER irc.darenet.org 1 947957852 947957852 J10 AB]]] :DareNET Client Server. [WRITE]: AB N MrFoo 1 947957852 ~me myhost.foo.net +diksw DAqAoB ABAAA :Mr Foo (foo@bar.com). [WRITE]: AB B #mychannel 946101324 ABAAA:o [WRITE]: AB EB [ READ]: PASS :54321 [ READ]: SERVER server1.darenet.org 1 947901540 947958150 J10 AFAD] :A Generic Server. [ READ]: AF S server2.darenet.org 2 0 947957585 P10 AZAD] 0 :[192.168.10.3] A Generic Server. [ READ]: AZ S server3.darenet.org 3 0 947957607 P10 AIAD] 0 :[192.168.10.5] A Generic Server. [ READ]: AF N Client1 1 947957573 Ident userhost.net +oiwg DAqAoB AFAAA :Generic Client. [ READ]: AZ N Client2 2 947957719 Ident userhost.net +iwg DAqAoB AZAAA :Generic Client. [ READ]: AI N Client3 3 947957742 Ident userhost.net +iwg DAqAoB AIAAA :Generic Client. [ READ]: AI N Client4 3 947958121 Ident userhost.net +iwg DAqAoB AIAAB :Generic Client. [ READ]: AF B #foo 947957734 +tink akey AIAAB,AIAAA:v,AZAAA:o :%*!*another@*.ban.com *!*foo@bar.net [ READ]: AF B #darenet 947957727 AIAAB,AZAAA:o [ READ]: AF B #another 946101321 AFAAA [ READ]: AF JU * +juped.darenet.org 3600 947958100 :Broken, please fix [ READ]: AF EB [WRITE]: AB EA [ READ]: AF EA

Continuous Operation
This section provides details of the various messages that can be sent after successfully linking to the network, and maintaining a synchronized state.

Server State Operations
As discussed earlier, a server object is created when a new server is introduced by means of the  message. A server object is destructed when an  message is received.

SQUIT
Removes a server from the network.

Syntax: 1       2         -1 SQ  [: ]


 *   - The name of the target server (not its numeric), without wildcards.
 *  - If the  parameter is equal to the link timestamp of the target server, or equal to 0, it applies; otherwise, the  message is ignored.
 * [OPTIONAL] - [:reason] - An optional reason indicating why the server is being disconnected.

Example: AZ SQ server2.darenet.org 1278767962 :Performing updates.

The message is propagated to all links except the link where the message cam from, and the target server if it is directly linked.

If a  message is to be sent to a directly linked target, the parameter will be the name of the local server. In this case, ircu sends a link timestamp of 0.

SETTIME
Sets the "clock" of one or all servers.

Syntax: 1          2 SE []


 *   - An epoch timestamp of the current time.
 * [OPTIONAL] [] - The numeric of the target server. This parameter is present if an oper issued "/settime ". In which case, the change will only apply to that specific server. If this parameter is not present, the change will be broadcasted to all servers.

Servers with RELIABLE_CLOCK will change the timestamp parameter of any  message to its own perception of what the current time is.

Example: AF SE 1278767962

Programmers reference: Client/Server Structures
This section provides information on the standard Client/Server structures, for easy reference during development.