Log in | Back to darenet.org

P10 Protocol

(Stream of Data, Lines, Line Termination)
m (Line: correct typo)
Line 59: Line 59:
NULL, CR and LF are disallowed in a line, any other character is allowed.
NULL, CR and LF are disallowed in a line, any other character is allowed.
-
{{Newuser_note | text= A parase can encounter a line which contains a NULL character. It ''may'' terminate the line at the first NULL character (removing anything after and including the first NULL character from the line).}}<br>
+
{{Newuser_note | text= A parser can encounter a line which contains a NULL character. It ''may'' terminate the line at the first NULL character (removing anything after and including the first NULL character from the line).}}<br>
=== Junk ===
=== Junk ===

Revision as of 16:28, 8 July 2010

Important
This page needs an update. Information posted here has been viewed as incorrect, incomplete, or out of date. Anyone is welcome to correct these flaws if this page has not been locked. Otherwise, contact a Support Team member and give them notice of this issue. Thank you.


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

In This Guide:

Terminology

Definitions of some commonly used terms in this document.

  • Byte - A unit of 8 bits of data.
  • Character - One byte, notated as a decimal number in the range 0-255, or a printable ASCII character (example: 65, 'A').
  • Char - Character.
  • String - A sequence of bytes.
  • Space - ASCII 32 ($20).
  • CR - Carriage return. '\r' (ASCII 13)
  • LF - Line feed (also known as 'new line'). '\n' (ASCII 10)
  • CRLF - Carriage return + Line feed (<CRLF>).
  • NULL - Character 0.
  • EOL - End of Line (line termination).
  • Parser - The implementation which receives and processes the stream.
  • Generate - Sending data which has not been received, as opposed to passing data on which has been received.
  • TS - Timestamp. An ASCII decimal notation of a date+time since Unix epoch.
  • Nick - Refers to a nickname.
  • Numnick = Refers to a client's numeric nickname.

"Must", "must not", "should", "may" are as described in RFC2119. Interpret "disallowed" as "must not."

Hexadecimal numbers in this document use pascal notation: a $ prefix. The number of hex digits (nibbles) represents the size of the data; for example, a byte can be anything between $00 and $ff.

Stream of Data, Lines, Line Termination

P10 is a 'text' protocol, that is, it is human readable and writable. Communication between two servers is done by means of a stream of bytes. The stream must be connected, reliable and ordered. So, the definition of the stream would be as follows:

<line><EOL><line><EOL> ... <junk>

Line termination (EOL)

When sending, line termination may be either <CRLF> or <LF>. It must not be anything else.

The parser must accept <LF> and <CRLF> as line termination. It may accept any other sequence of <CR> and <LF> as EOL. It must not parse anything else as line termination.

Line

A line (also commonly referred to as a "message") is defined as a sequence of characters, minimum length being 1 byte, maximum length 510 bytes, not including the EOL (which makes a total of 512 bytes). If a parser encounters a line with a length of 0 bytes, it must be silently ignored, and it must not do anything else. A line which is longer than the maximum length is disallowed.

NULL, CR and LF are disallowed in a line, any other character is allowed.

A parser can encounter a line which contains a NULL character. It may terminate the line at the first NULL character (removing anything after and including the first NULL character from the line).

Junk

Any data between the last EOL and the end of the stream. It must not be parsed as a line.

P10 Base64

The P10 protocol uses a modified base64 notation for numeric nicks, and for the IP parameter in the NICK message. It uses the following set of 64 characters, in the sequence from 0 to 63 (henceforth referred to as the P10 base64 characters):

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]

A P10 base64 string is a sequence of P10 base64 characters, with a minimum length of 1 character. It must not contain any other character. If the string has a length of more than one character, the string begins with the most significant character and ends with the least significant character.

P10 base64 strings are case sensitive.

Numerics

The P10 protocol uses a scheme of "numerics" to uniquely identify a client or server 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).

These numerics are encoded into a base64 string to maintain human readable data flow, and to reduce the size of messages.

Server numerics consist of 2 characters, with the minimum, 0, being represented by "AA", and the maximum, 4095, being represented by "]]". Client numerics are 3 characters in length, with the minimum, 0, being represented by "AAA", and the maximum, 262,143, being represented by "]]]". The unique identifier (known as a numnick) of a client on the network consists of a combination of both the server and client numeric in the format SSCCC - a total of 5 base64 characters.

A server has a maximum client numeric, which is sent in the SERVER message. A client numeric on a server, ANDed with the maximum server numeric, must be unique. For example, if the server YY's max client numeric is YYA[[ (4095), clients YYBXX and YYCXX cannot exist at the same time. Doing this would result in a "numeric collision", which is a protocol violation. However, such numerics which occupy the same "slot" are not identical - a message sent to use YYBXX in this example must not reach user YYCXX.

Taken what we know from above, let's go through an example. Consider a server "peanuts.darenet.org" which as a numeric of 2, translating to "AC" in base64. On this server exists a client, whom has been allocated the numeric 63 (which translates to "AA]" in base64); therefore, the unique identifier 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.

The P10 protocol defines two types of numerics: short numerics and extended numerics. For the purpose of this document, we have chosen to use extended numerics, as implemented by Undernet, DareNET and most other networks utilizing the P10 protocol.

Syntax of a line/message

The source, command, and parameters are separated by spaces.

<source> <command> [<parameters>]

One must send only the short command token. One must parse both the short command token and its long unabbreviated name, and if one does, they must be considered equivalent; for example N = NICK. So if I say "receives a NICK message" it may actually be a N token.

Command tokens are uppercase. One must not send lowercase command tokens. One may parse them.

If source begins with a colon, it (except for the colon) is the name; otherwise, it is a numeric. One must only send messages with a numeric source prefix, except for the initial PASS and SERVER command, which are not prefixed.

If the source does not exist, if the command is SQUIT or KILL (or their respective short token), the message must be parsed anyway, with the directly linked server from which the message came as the source; otherwise, the message must be ignored.

If the source exists but the message comes from the wrong direction, it must be ignored. The direction of a source is defined as the link over which the corresponding message was received, that originally introduced the source. A link is the connection with another server.

A message may have up to 15 parameters. Parameters are separated by spaces.

The last parameter may be prefixed by a colon; this allows the last parameter to have spaces, or to have a length of 0 characters. For example: <source> <command> <param1> <paramN> :<last parameter>. A parser must be able to parse messages with colon prefixed last parameter, and without. For example, parameters "a b c" and "a b :c" are equivalent.

Token Table

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

Message Token
PRIVMSG P
WHO H
WHOIS W
WHOWAS X
USER USER
NICK N
SERVER S
LIST LIST
TOPIC T
INVITE I
VERSION V
QUIT Q
SQUIT SQ
KILL D
INFO F
LINKS LI
STATS R
HELP HELP
ERROR Y
AWAY A
CONNECT CO
MAP MAP
PING G
PONG Z
OPER OPER
PASS PA
WALLOPS WA
DESYNCH DS
TIME TI
SETTIME SE
RPING RI
RPING RO
NAMES E
ADMIN AD
TRACE TR
NOTICE O
WALLCHOPS WC
WALLHOPS WH
CPRIVMSG CP
CNOTICE CN
JOIN J
PART L
LUSERS LU
MOTD MO
MODE M
KICK K
USERHOST USERHOST
USERIP USERIP
ISON ISON
SQUERY SQUERY
SERVLIST SERVLIST
SERVSET SERVSET
REHASH REHASH
RESTART RESTART
CLOSE CLOSE
DIE DIE
HASH HASH
DNS DNS
SILENCE U
GLINE GL
BURST B
CREATE C
DESTRUCT DE
END_OF_BURST EB
END_OF_BURST_ACK EA
PROTO PROTO
JUPE JU
OPMODE OM
CLEARMODE CM
ACCOUNT AC

Registration and Synchronization

Server Registration and Authentication

After a TCP connection has been established, the server initially introduces itself via a "PASS" message as follows:

PASS :[PASSWORD]

"PASSWORD" is simply compared with the password present in the destination servers config file, and is used to confirm credentials after the "SERVER" message has been received, as follows:

SERVER [SERVERNAME] [HOPCOUNT] [START TIME] [LINK TIME] [PROTOCOL] [NUMERIC/MAXCONN] :[DESCRIPTION

For example:

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

Notes:

  1. The SERVER message, indicating this connection wishes to introduce a new server to the network.
  2. The name of the server you are introducing, a valid server name consists of [..defn..].
  3. The hop count of the server you are introducing, this is always 1 when you are introducing yourself.
  4. The epoch timestamp specifying when the ircd was started.
  5. The epoch timestamp specifying the time the server initiated the link to the network.
  6. The Protocol identifier of this server.
    1. This token informs the network which protocol it is compliant with, eg: If it is a P10 compliant server, then the token will be "P10".
    2. If the server being introduced has not yet successfully synced its database with the network (Completed its net.burst), then the Protocol token should be prefixed with a J, instead of a P (Eg: J10) to indicate it is currently still joining the network.
    3. The protocol token should always be JXX when the server is introducing itself.
  7. The numeric, and maximum connections identifier for this server.
    1. This token is formatted exactly the same as a client numeric is formatted. The first 2 characters identify the server's numeric, whilst in this situation, the final 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 a 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 it's 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 maybe get messages destined to the old user.
    2. The example "AA]]]" shows that this is a server with numeric 0, which will generate client numerics up to 262,143.
  8. This final parameter simply consists of a textual description of the server prefixed by a colon. This is displayed in a clients WHOIS line, as well as in the LINKS reply. By convention, if this is a leaf server it contains the servers IP in square brackets at the beginning of the string,

Network Database Resynchronization

After the connection (link) has been established and verified, the next step is to synchronize the database of client / server / channel information between the two servers.

SERVER Messages

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

[OWNING SERVER PREFIX] S [SERVERNAME] [HOPCOUNT] [START TIME] [LINK TIME] [PROTOCOL] [NUMERIC/MAXCONN] 0 :[DESCRIPTION]

The syntax of this message is almost identical to the originally received server message, with the exception being that the message is prefixed with a numeric to indicate which server sent this message (and also, therefore, which hub this new server is linked too). There is also a fixed "0" present before the Description field, which is just a placeholder for future use and currently unused.

NICK Messages

Client information is transmitted via "NICK" messages, of the following format:

[NUMERIC PREFIX] N [NICK] [HOPCOUNT] [TIMESTAMP] [USERNAME] [HOST] <+modes> [BASE64 IP] [NUMERIC] :[USERINFO]

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. The numeric of the server sending this message. (hence, owning this client).
  2. The "NICK" token.
  3. The nickname of this client, currently max 30 chars.
  4. The "Hopcount" of this client, i.e: how many servers away it is on.
  5. The epoch timestamp indicating when the user was created.
  6. The "User" part of the user@host mask.
  7. the "Host" part of the user@host mask.
  8. [Optional]: User modes. If present, this is always +<user modes for this client>. Note that the special +r usermode is followed by the client's account name; see the documentation for ACCOUNT.
  9. The real IP address of this client, a Base64 encoded 32bit int.
  10. This client's numeric, in SSCCC format.
  11. Free format user info line.

BURST Messages

Channel details and membership information is synchronized on one (or more) "BURST" messages for each channel that exists, formatted as follows:

[NUMERIC PREFIX] B [CHANNEL] [CREATION TIMESTAMP] <+MODES> <ARG1> <ARG2> [MEMBER LIST] <:%BANS>

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

Notes:

  1. The numeric of the server sending this message.
  2. The "BURST" token.
  3. The name of the channel to which this data belongs. Currently #Channel and +Channel names can be sent in a BURST message, &Channels are not because by definition they are local to the server.
  4. The epoch timestamp indicating when the channel was created.
  5. [Optional]: Channel Modes.
    1. The channel may have a number of modes set, a swell as relevant mode arguments in the following 2 parameters.
  6. [Optional]: Channel Key, this parameter is present if the channel modes contain a "k" mode.
  7. [Optional]: Channel Limit, this parameter is present if the channel modes contain a "l" mode.
  8. A comma seperated list of client numerics, with the following specific formatting rules to indicate +o, +v and +ov channel members.
    1. Numerics can have the following symbols appended on them; ":ohv", ":oh", ":ov", ":hv", ":v", ":h" or ":o". These indicate that this numeric is either Opped (:o), Halfoped (:h) Voiced (:v) and so on. This state applies to the numeric it is attached too, and all subsequent numerics until another state is encountered. For Example: AAABA:ov, AAABB:o,AAABC,AAABD,AAABE:v,AAABZ. Here, AAABA is both opped, and voiced, AAABB, AAABC and AAABD are opped leaving AAABE and AAABZ voiced.
    2. The first numeric of the member list will always contain a state symbol.
  9. A space seperated list of bans present in the channel. The start of the ban stream is indicated by a ":%", everything following the ":%" is the ban list.

For Example:
:%*!*@*.foobar.net another!ban@*.com *!*fred@a.host.co.uk

Would add the following bans to the channel:
*!*@*.foobar.net
another!ban@*.com
*!*fred@a.host.co.uk

NOTE: We BURST excepts in the same manner.

If the length of a BURST message exceeds the maximum lengh of a line (512 characters) then the remaining channel members/bans are sent in subsequent BURST lines. The subsequent burst lines are only used to add additional members to the channel, and if necessary, channel bans. There will be no "Mode" parameters present. A sample additional burst line would be:

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

JUPE Messages

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

[NUMERIC PREFIX] JU * (+|-)[SERVER NAME] [LIFETIME] [LAST MOD] :[REASON]

For example:

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

Notes:

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

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.

S1: Sends Password.
S1: Sends initial SERVER message.

S2 Confirms S1 has the correct credentials, and if so, proceeds. If not, S1 is squit with a relevant reason.

S2: Sends Password.
S2: Sends initial SERVER message.

S1 Confirms S2 has the correct credentials, and if so, proceeds. If not, S2 is squit with a relevant reason.

The following occurs asynchronously, however it is shown separately below for simplicity.

S1: Sends all the servers it is aware of as a stream of SERVER messages.
S1: Sends all the clients it is aware of as a stream of NICK messages.
S1: Sends the database of channel states on the network, as a stream of BURST messages.
S1: Sends all the jupes it is aware of as a stream of JUPE messages.
S1: Sends a END_OF_BURST token (EB) to indicate it has finished sending.

S2: Sends all the servers it is aware of as a stream of SERVER messages.
S2: Sends all the clients it is aware of as a stream of NICK messages.
S2: Sends the database of channel states on the network, as a stream of BURST messages.
S2: Sends all the jupes it is aware of as a stream of JUPE messages.
S2: Sends a END_OF_BURST token (EB) to indicate it has finished sending.

S2: Sends an EOB_ACK token (EA) to indicate it has succesfully recieved the END_OF_BURST from S1
S1: Sends an EOB_ACK token (EA) to indicate it has succesfully recieved the END_OF_BURST from S2

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 synchronizing the channel/user database.

Channel State Operations

There are a number of messages that can modify the state of a channel, these are:

MODE

The MODE message can modify channel modes and bans, and also give or take operator/halfop//voice status from channel members.

[NUMERIC PREFIX] M [CHANNEL] (+|-)[MODESTRING] <MODESTRING PARAMETERS>

For example:

1     2 3        4        5
AZAAA M #darenet +stinlko 500 TestKey BAC

Notes:

  1. The numeric of the user issuing this MODE command. It can be assumed this user is opped on the target channel.
  2. The "MODE" token.
  3. The target channel.
  4. The "Mode string".
    1. This consists of up to 6 '+' or '-' (add or remove) prefixed channel modes. (If no '+' or '-' are specified, a '+' is assumed unless a '-' has been encountered previously in the mode string). For example, '+s+t+n-l-io' is a valid mode string, as is '+stnmov'.
  5. The "Mode string Parameters".
    1. This is a matching list of parameters to the modes supplied in the "Modestring".
    2. Example: If the Modestring is "+stnlo", a typical parameter string would be "500 AZAAA". The first 3 modes, 's', 't' and 'n' do not require parameters, so non are present. The following two, 'l' and 'o' both require parameters, so they are 500 and AZAAA respectively (This sets the channel limit to 500 users, and ops the numeric AZAAA).

NOTE: The "MODE" message is also used to modify a client's user modes, not just channel modes.

OPMODE

The OPMODE message is identical in syntax to the MODE message, however it will only ever have an operator as the source. It is likely that the source of this mode will not have ops in the target channel, but it should succeed never the less.

JOIN

PART

KICK

TOPIC

CLEARMODE

[NUMERIC PREFIX] CM [CHANNEL] [MODES]

Client State Operations

NICK

AZAAA N Nick2 955423230

MODE

AZAAA M Nick2 :+odi

ACCOUNT

AX AC AZAAA oper

The ACCOUNT message provides a way for servers, such as the channel service server, to set the account name information that is associated with a client. Once set, it cannot be unset or changed, and will be propagated in NICK during net bursts using the special user mode +r followed by the account name.

Channel/Client Messaging

PRIVMSG

NOTICE

CNOTICE

CPRIVMSG

Programmers reference: Client/Server Structures

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