Home docs pia PIA Types
Post

PIA Types

This page describes common data structures that are used by the Pia library.

  1. InetAddress
  2. StationAddress
  3. StationLocation
  4. StationConnectionInfo

The following ids are used in various places:

  1. Constant id
  2. Variable id
  3. Service variable id

InetAddress

Up to 5.10:

This structure can only represent IPv4 addresses.

OffsetSizeDescription
0x04Address
0x42Port

5.11 - 6.30:

This structure can represent both IPv4 and IPv6 addresses. Which encoding is used depends on the context.

OffsetSizeDescription
0x00, 4 or 16Address
0x102Port

StationAddress

Up to 4.10:

OffsetSizeDescription
0x06Inet address
0x62Extension id

5.2 - 5.44:

OffsetSizeDescription
0x02, 6 or 18Inet address

6.16 - 6.30:

OffsetSizeDescription
0x016Address
0x102Port

StationLocation

The station location holds information that allows Pia to connect to a given station. Many fields are directly taken from a station url, when NEX is used.

Up to 4.10:

TypeDescription
StationAddressStation address
Uint32Constant id (PID)
Uint32Variable id (CID)
Uint32Service variable id (RVCID)
Uint8URL type
Uint8NEX stream id (sid)
Uint8NEX stream type (stream)
Uint8NAT mapping (natm)
Uint8NAT filtering (natf)
Uint8NAT flags (type)
Uint8probeinit

5.2 - 5.9:

TypeDescription
StationAddressStation address
Uint64Constant id (PID)
Uint32Variable id (CID)
Uint32Service variable id (RVCID)
Uint8URL type
Uint8NEX stream id (sid)
Uint8NEX stream type (stream)
Uint8NAT mapping (natm)
Uint8NAT filtering (natf)
Uint8NAT flags (type)
Uint8probeinit
InetAddressRelay address

5.10:

TypeDescription
InetAddressPublic address
InetAddressPrivate address
InetAddressRelay address
Uint64Constant id (PID)
Uint32Variable id (CID)
Uint80x3: NAT filtering (natf)
0xC: NAT mapping (natm)
0xF0: NAT type
Uint8NAT flags (type)
Uint8probeinit
Uint8Is private address available

5.11 - 5.44:

TypeDescription
Uint8Size of public address
Uint8Size of private address
InetAddressPublic address
InetAddressPrivate address
InetAddressRelay address (IPv4)
Uint64Constant id (PID)
Uint32Variable id (CID)
Uint32Service variable id (RVCID)
Uint80x3: NAT filtering (natf)
0xC: NAT mapping (natm)
0xF0: NAT type
Uint8NAT flags (type)
Uint8probeinit
Uint8Is private address available

6.16 - 6.30:

TypeDescription
Uint8Address size
StationAddressAddress
Uint64Constant id
Uint16Variable id
Uint80x3: NAT filtering
0xC: NAT mapping
0x10: Is IPv6

NEX URL Type

The URL type depends on the scheme of the given station url. It is always 0 or 1 in practice.

ValueScheme
0Invalid
1prudp
2prudps
3udp

NAT Mapping

ValueDescription
0Unknown
1Endpoint independent mapping
2Endpoint dependent mapping

NAT Filtering

ValueDescription
0Unknown
1Port independent filtering
2Port dependent filtering

NAT Flags

FlagDescription
1Is behind NAT
2Is public

NAT Type

The NAT type determines how well the Switch is able to set up peer-to-peer connections. A is the best and F is the worst. The NAT type is also shown in the system settings if you perform a connection test.

The NAT type is used during host migration, giving players with a better NAT type a higher priority.

ValueType
0F
1A
2B
3C
4D

StationConnectionInfo

Up to 5.9:

TypeDescription
StationLocationPublic location
StationLocationPrivate location

In Pia version 5.10, the station connection info structure was removed.

Constant ID

The constant id uniquely identifies a station, and never changes, even across sessions. The constant id depends on the network type.

NEX (Up to 5.44):

The constant id is the same as your principal id (pid).

LAN (Up to 5.9):

The constant id is generated from your local IP address and port: ip << 32 | port

LDN (Up to 5.9):

The constant id is generated from your MAC address: mac[2] << 56 | mac[4] << 48 | mac[5] << 40 | mac[3] << 32 | mac[1] << 24 | mac[0] << 16.

Variable ID

The variable id uniquely identifies a station in the current session. Unlike the constant id, it may change across sessions. The variable id depends on the network type:

NEX (Up to 5.44):

The variable id is the same as your connection id (CID).

LAN (Up to 5.9):

The variable is set to the current system tick (nn::os::GetSystemTick()) at the start of the session.

LDN (Up to 5.9):

The variable is set to the current system tick (nn::os::GetSystemTick()) at the start of the session.

Service Variable ID

Like the variable id, the service variable id uniquely identifies a station in the current session and may change across sessions. The service variable id depends on the network type:

NEX (Up to 5.44):

The services variable id is your Rendez-Vous connection id (RVCID). This is received from the server when the client registers itself with the secure connection protocol.

LAN (Up to 5.9):

The service variable id is generated from your local IP address and port: (ip & 0xFFFF) << 16 | port.

LDN (Up to 5.9):

The service variable id is the CRC32 hash of your MAC address.

Contents