2014-07-04 06:42:24 +00:00
|
|
|
package multiaddr
|
|
|
|
|
2017-07-20 21:36:21 +00:00
|
|
|
// You **MUST** register your multicodecs with
|
|
|
|
// https://github.com/multiformats/multicodec before adding them here.
|
2014-07-07 08:25:20 +00:00
|
|
|
const (
|
2018-12-20 11:10:02 +00:00
|
|
|
P_IP4 = 0x0004
|
|
|
|
P_TCP = 0x0006
|
2019-09-19 00:13:14 +00:00
|
|
|
P_DNS = 0x0035 // 4 or 6
|
2019-09-18 06:19:59 +00:00
|
|
|
P_DNS4 = 0x0036
|
|
|
|
P_DNS6 = 0x0037
|
|
|
|
P_DNSADDR = 0x0038
|
2018-12-20 11:10:02 +00:00
|
|
|
P_UDP = 0x0111
|
|
|
|
P_DCCP = 0x0021
|
|
|
|
P_IP6 = 0x0029
|
|
|
|
P_IP6ZONE = 0x002A
|
2022-06-19 16:15:36 +00:00
|
|
|
P_IPCIDR = 0x002B
|
2018-12-20 11:10:02 +00:00
|
|
|
P_QUIC = 0x01CC
|
2022-04-06 11:37:31 +00:00
|
|
|
P_WEBTRANSPORT = 0x01D1
|
2018-12-20 11:10:02 +00:00
|
|
|
P_SCTP = 0x0084
|
2019-09-18 05:53:31 +00:00
|
|
|
P_CIRCUIT = 0x0122
|
2018-12-20 11:10:02 +00:00
|
|
|
P_UDT = 0x012D
|
|
|
|
P_UTP = 0x012E
|
|
|
|
P_UNIX = 0x0190
|
|
|
|
P_P2P = 0x01A5
|
2021-05-26 13:04:06 +00:00
|
|
|
P_IPFS = 0x01A5 // alias for backwards compatibility
|
2018-12-20 11:10:02 +00:00
|
|
|
P_HTTP = 0x01E0
|
2021-05-26 13:04:06 +00:00
|
|
|
P_HTTPS = 0x01BB // deprecated alias for /tls/http
|
2018-12-20 11:10:02 +00:00
|
|
|
P_ONION = 0x01BC // also for backwards compatibility
|
|
|
|
P_ONION3 = 0x01BD
|
2019-04-05 19:15:05 +00:00
|
|
|
P_GARLIC64 = 0x01BE
|
|
|
|
P_GARLIC32 = 0x01BF
|
2018-12-20 11:10:02 +00:00
|
|
|
P_P2P_WEBRTC_DIRECT = 0x0114
|
2021-05-26 13:04:06 +00:00
|
|
|
P_TLS = 0x01c0
|
2021-07-01 23:41:44 +00:00
|
|
|
P_NOISE = 0x01c6
|
2019-09-18 06:07:40 +00:00
|
|
|
P_WS = 0x01DD
|
2021-05-26 13:04:06 +00:00
|
|
|
P_WSS = 0x01DE // deprecated alias for /tls/ws
|
2021-09-19 16:12:54 +00:00
|
|
|
P_PLAINTEXTV2 = 0x706c61
|
2015-01-18 05:12:54 +00:00
|
|
|
)
|
|
|
|
|
2018-05-24 14:48:52 +00:00
|
|
|
var (
|
2018-07-18 16:09:29 +00:00
|
|
|
protoIP4 = Protocol{
|
|
|
|
Name: "ip4",
|
|
|
|
Code: P_IP4,
|
|
|
|
VCode: CodeToVarint(P_IP4),
|
|
|
|
Size: 32,
|
|
|
|
Path: false,
|
|
|
|
Transcoder: TranscoderIP4,
|
|
|
|
}
|
|
|
|
protoTCP = Protocol{
|
|
|
|
Name: "tcp",
|
|
|
|
Code: P_TCP,
|
|
|
|
VCode: CodeToVarint(P_TCP),
|
|
|
|
Size: 16,
|
|
|
|
Path: false,
|
|
|
|
Transcoder: TranscoderPort,
|
|
|
|
}
|
2019-09-19 00:13:14 +00:00
|
|
|
protoDNS = Protocol{
|
|
|
|
Code: P_DNS,
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Name: "dns",
|
|
|
|
VCode: CodeToVarint(P_DNS),
|
|
|
|
Transcoder: TranscoderDns,
|
|
|
|
}
|
2019-09-18 06:19:59 +00:00
|
|
|
protoDNS4 = Protocol{
|
|
|
|
Code: P_DNS4,
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Name: "dns4",
|
|
|
|
VCode: CodeToVarint(P_DNS4),
|
|
|
|
Transcoder: TranscoderDns,
|
|
|
|
}
|
|
|
|
protoDNS6 = Protocol{
|
|
|
|
Code: P_DNS6,
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Name: "dns6",
|
|
|
|
VCode: CodeToVarint(P_DNS6),
|
|
|
|
Transcoder: TranscoderDns,
|
|
|
|
}
|
|
|
|
protoDNSADDR = Protocol{
|
|
|
|
Code: P_DNSADDR,
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Name: "dnsaddr",
|
|
|
|
VCode: CodeToVarint(P_DNSADDR),
|
|
|
|
Transcoder: TranscoderDns,
|
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoUDP = Protocol{
|
|
|
|
Name: "udp",
|
|
|
|
Code: P_UDP,
|
|
|
|
VCode: CodeToVarint(P_UDP),
|
|
|
|
Size: 16,
|
|
|
|
Path: false,
|
|
|
|
Transcoder: TranscoderPort,
|
|
|
|
}
|
|
|
|
protoDCCP = Protocol{
|
|
|
|
Name: "dccp",
|
|
|
|
Code: P_DCCP,
|
|
|
|
VCode: CodeToVarint(P_DCCP),
|
|
|
|
Size: 16,
|
|
|
|
Path: false,
|
|
|
|
Transcoder: TranscoderPort,
|
|
|
|
}
|
|
|
|
protoIP6 = Protocol{
|
|
|
|
Name: "ip6",
|
|
|
|
Code: P_IP6,
|
|
|
|
VCode: CodeToVarint(P_IP6),
|
|
|
|
Size: 128,
|
|
|
|
Transcoder: TranscoderIP6,
|
|
|
|
}
|
2022-06-19 16:15:36 +00:00
|
|
|
protoIPCIDR = Protocol{
|
|
|
|
Name: "ipcidr",
|
|
|
|
Code: P_IPCIDR,
|
|
|
|
VCode: CodeToVarint(P_IPCIDR),
|
|
|
|
Size: 8,
|
|
|
|
Transcoder: TranscoderIPCIDR,
|
|
|
|
}
|
2018-05-24 14:48:52 +00:00
|
|
|
// these require varint
|
2018-05-27 22:57:53 +00:00
|
|
|
protoIP6ZONE = Protocol{
|
|
|
|
Name: "ip6zone",
|
|
|
|
Code: P_IP6ZONE,
|
|
|
|
VCode: CodeToVarint(P_IP6ZONE),
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Path: false,
|
|
|
|
Transcoder: TranscoderIP6Zone,
|
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoSCTP = Protocol{
|
|
|
|
Name: "sctp",
|
|
|
|
Code: P_SCTP,
|
|
|
|
VCode: CodeToVarint(P_SCTP),
|
|
|
|
Size: 16,
|
|
|
|
Transcoder: TranscoderPort,
|
2018-05-24 14:48:52 +00:00
|
|
|
}
|
2019-09-18 05:53:31 +00:00
|
|
|
|
|
|
|
protoCIRCUIT = Protocol{
|
|
|
|
Code: P_CIRCUIT,
|
|
|
|
Size: 0,
|
|
|
|
Name: "p2p-circuit",
|
|
|
|
VCode: CodeToVarint(P_CIRCUIT),
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:36:21 +00:00
|
|
|
protoONION2 = Protocol{
|
2018-07-18 16:09:29 +00:00
|
|
|
Name: "onion",
|
2018-12-01 01:09:02 +00:00
|
|
|
Code: P_ONION,
|
|
|
|
VCode: CodeToVarint(P_ONION),
|
2018-07-18 16:09:29 +00:00
|
|
|
Size: 96,
|
|
|
|
Transcoder: TranscoderOnion,
|
2018-05-24 14:48:52 +00:00
|
|
|
}
|
2018-11-08 08:36:21 +00:00
|
|
|
protoONION3 = Protocol{
|
|
|
|
Name: "onion3",
|
|
|
|
Code: P_ONION3,
|
|
|
|
VCode: CodeToVarint(P_ONION3),
|
|
|
|
Size: 296,
|
|
|
|
Transcoder: TranscoderOnion3,
|
|
|
|
}
|
2018-12-01 00:55:52 +00:00
|
|
|
protoGARLIC64 = Protocol{
|
|
|
|
Name: "garlic64",
|
|
|
|
Code: P_GARLIC64,
|
|
|
|
VCode: CodeToVarint(P_GARLIC64),
|
2018-12-13 09:53:17 +00:00
|
|
|
Size: LengthPrefixedVarSize,
|
2018-12-01 00:55:52 +00:00
|
|
|
Transcoder: TranscoderGarlic64,
|
2018-11-08 08:36:21 +00:00
|
|
|
}
|
2019-03-29 18:52:24 +00:00
|
|
|
protoGARLIC32 = Protocol{
|
|
|
|
Name: "garlic32",
|
|
|
|
Code: P_GARLIC32,
|
|
|
|
VCode: CodeToVarint(P_GARLIC32),
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Transcoder: TranscoderGarlic32,
|
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoUTP = Protocol{
|
|
|
|
Name: "utp",
|
|
|
|
Code: P_UTP,
|
|
|
|
VCode: CodeToVarint(P_UTP),
|
2018-06-23 01:39:50 +00:00
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoUDT = Protocol{
|
|
|
|
Name: "udt",
|
|
|
|
Code: P_UDT,
|
|
|
|
VCode: CodeToVarint(P_UDT),
|
2018-06-23 01:39:50 +00:00
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoQUIC = Protocol{
|
|
|
|
Name: "quic",
|
|
|
|
Code: P_QUIC,
|
|
|
|
VCode: CodeToVarint(P_QUIC),
|
2018-06-23 01:34:55 +00:00
|
|
|
}
|
2022-04-06 11:37:31 +00:00
|
|
|
protoWEBTRANSPORT = Protocol{
|
|
|
|
Name: "webtransport",
|
|
|
|
Code: P_WEBTRANSPORT,
|
|
|
|
VCode: CodeToVarint(P_WEBTRANSPORT),
|
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoHTTP = Protocol{
|
|
|
|
Name: "http",
|
|
|
|
Code: P_HTTP,
|
|
|
|
VCode: CodeToVarint(P_HTTP),
|
2018-06-23 01:34:55 +00:00
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoHTTPS = Protocol{
|
|
|
|
Name: "https",
|
|
|
|
Code: P_HTTPS,
|
|
|
|
VCode: CodeToVarint(P_HTTPS),
|
2015-01-09 13:51:16 +00:00
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoP2P = Protocol{
|
2019-11-01 21:22:21 +00:00
|
|
|
Name: "p2p",
|
2018-07-18 16:09:29 +00:00
|
|
|
Code: P_P2P,
|
|
|
|
VCode: CodeToVarint(P_P2P),
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Transcoder: TranscoderP2P,
|
2015-01-09 13:51:16 +00:00
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
protoUNIX = Protocol{
|
|
|
|
Name: "unix",
|
|
|
|
Code: P_UNIX,
|
|
|
|
VCode: CodeToVarint(P_UNIX),
|
|
|
|
Size: LengthPrefixedVarSize,
|
|
|
|
Path: true,
|
|
|
|
Transcoder: TranscoderUnix,
|
2016-04-29 21:16:41 +00:00
|
|
|
}
|
2018-12-20 11:10:02 +00:00
|
|
|
protoP2P_WEBRTC_DIRECT = Protocol{
|
|
|
|
Name: "p2p-webrtc-direct",
|
|
|
|
Code: P_P2P_WEBRTC_DIRECT,
|
|
|
|
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
|
|
|
|
}
|
2021-05-26 13:04:06 +00:00
|
|
|
protoTLS = Protocol{
|
|
|
|
Name: "tls",
|
|
|
|
Code: P_TLS,
|
|
|
|
VCode: CodeToVarint(P_TLS),
|
2021-07-01 23:41:44 +00:00
|
|
|
}
|
|
|
|
protoNOISE = Protocol{
|
|
|
|
Name: "noise",
|
|
|
|
Code: P_NOISE,
|
|
|
|
VCode: CodeToVarint(P_NOISE),
|
2021-05-26 13:04:06 +00:00
|
|
|
}
|
2021-09-19 16:12:54 +00:00
|
|
|
protoPlaintextV2 = Protocol{
|
|
|
|
Name: "plaintextv2",
|
|
|
|
Code: P_PLAINTEXTV2,
|
|
|
|
VCode: CodeToVarint(P_PLAINTEXTV2),
|
|
|
|
}
|
2019-09-18 06:07:40 +00:00
|
|
|
protoWS = Protocol{
|
|
|
|
Name: "ws",
|
|
|
|
Code: P_WS,
|
|
|
|
VCode: CodeToVarint(P_WS),
|
|
|
|
}
|
2020-02-29 02:58:05 +00:00
|
|
|
protoWSS = Protocol{
|
|
|
|
Name: "wss",
|
|
|
|
Code: P_WSS,
|
|
|
|
VCode: CodeToVarint(P_WSS),
|
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
)
|
2014-11-19 21:01:52 +00:00
|
|
|
|
2018-07-18 16:09:29 +00:00
|
|
|
func init() {
|
|
|
|
for _, p := range []Protocol{
|
|
|
|
protoIP4,
|
|
|
|
protoTCP,
|
2019-09-19 00:13:14 +00:00
|
|
|
protoDNS,
|
2019-09-18 06:19:59 +00:00
|
|
|
protoDNS4,
|
|
|
|
protoDNS6,
|
|
|
|
protoDNSADDR,
|
2018-07-18 16:09:29 +00:00
|
|
|
protoUDP,
|
|
|
|
protoDCCP,
|
|
|
|
protoIP6,
|
2018-05-27 22:57:53 +00:00
|
|
|
protoIP6ZONE,
|
2022-06-19 16:15:36 +00:00
|
|
|
protoIPCIDR,
|
2018-07-18 16:09:29 +00:00
|
|
|
protoSCTP,
|
2019-09-18 05:53:31 +00:00
|
|
|
protoCIRCUIT,
|
2018-11-08 08:36:21 +00:00
|
|
|
protoONION2,
|
|
|
|
protoONION3,
|
2018-12-01 00:55:52 +00:00
|
|
|
protoGARLIC64,
|
2019-03-29 18:52:24 +00:00
|
|
|
protoGARLIC32,
|
2018-07-18 16:09:29 +00:00
|
|
|
protoUTP,
|
|
|
|
protoUDT,
|
|
|
|
protoQUIC,
|
2022-04-06 11:37:31 +00:00
|
|
|
protoWEBTRANSPORT,
|
2018-07-18 16:09:29 +00:00
|
|
|
protoHTTP,
|
|
|
|
protoHTTPS,
|
|
|
|
protoP2P,
|
|
|
|
protoUNIX,
|
2018-12-20 11:10:02 +00:00
|
|
|
protoP2P_WEBRTC_DIRECT,
|
2021-05-26 13:04:06 +00:00
|
|
|
protoTLS,
|
2021-07-01 23:41:44 +00:00
|
|
|
protoNOISE,
|
2019-09-18 06:07:40 +00:00
|
|
|
protoWS,
|
2020-02-29 02:58:05 +00:00
|
|
|
protoWSS,
|
2021-09-19 16:12:54 +00:00
|
|
|
protoPlaintextV2,
|
2018-07-18 16:09:29 +00:00
|
|
|
} {
|
|
|
|
if err := AddProtocol(p); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-11-19 21:01:52 +00:00
|
|
|
}
|
2018-07-18 16:09:29 +00:00
|
|
|
|
|
|
|
// explicitly set both of these
|
|
|
|
protocolsByName["p2p"] = protoP2P
|
|
|
|
protocolsByName["ipfs"] = protoP2P
|
2014-11-19 21:01:52 +00:00
|
|
|
}
|