protocols.go 6.48 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2
package multiaddr

3 4
// You **MUST** register your multicodecs with
// https://github.com/multiformats/multicodec before adding them here.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
5
const (
backkem's avatar
backkem committed
6 7
	P_IP4               = 0x0004
	P_TCP               = 0x0006
Steven Allen's avatar
Steven Allen committed
8
	P_DNS               = 0x0035 // 4 or 6
godcong's avatar
godcong committed
9 10 11
	P_DNS4              = 0x0036
	P_DNS6              = 0x0037
	P_DNSADDR           = 0x0038
backkem's avatar
backkem committed
12 13 14 15
	P_UDP               = 0x0111
	P_DCCP              = 0x0021
	P_IP6               = 0x0029
	P_IP6ZONE           = 0x002A
Marco Munizaga's avatar
Marco Munizaga committed
16
	P_IPCIDR            = 0x002B
backkem's avatar
backkem committed
17
	P_QUIC              = 0x01CC
Marten Seemann's avatar
Marten Seemann committed
18
	P_WEBTRANSPORT      = 0x01D1
Marten Seemann's avatar
Marten Seemann committed
19
	P_CERTHASH          = 0x01D2
backkem's avatar
backkem committed
20
	P_SCTP              = 0x0084
godcong's avatar
godcong committed
21
	P_CIRCUIT           = 0x0122
backkem's avatar
backkem committed
22 23 24 25
	P_UDT               = 0x012D
	P_UTP               = 0x012E
	P_UNIX              = 0x0190
	P_P2P               = 0x01A5
Pavel Karpy's avatar
Pavel Karpy committed
26
	P_IPFS              = 0x01A5 // alias for backwards compatibility
backkem's avatar
backkem committed
27
	P_HTTP              = 0x01E0
Pavel Karpy's avatar
Pavel Karpy committed
28
	P_HTTPS             = 0x01BB // deprecated alias for /tls/http
backkem's avatar
backkem committed
29 30
	P_ONION             = 0x01BC // also for backwards compatibility
	P_ONION3            = 0x01BD
31 32
	P_GARLIC64          = 0x01BE
	P_GARLIC32          = 0x01BF
backkem's avatar
backkem committed
33
	P_P2P_WEBRTC_DIRECT = 0x0114
Pavel Karpy's avatar
Pavel Karpy committed
34
	P_TLS               = 0x01c0
Marten Seemann's avatar
Marten Seemann committed
35
	P_NOISE             = 0x01c6
godcong's avatar
godcong committed
36
	P_WS                = 0x01DD
Pavel Karpy's avatar
Pavel Karpy committed
37
	P_WSS               = 0x01DE // deprecated alias for /tls/ws
38
	P_PLAINTEXTV2       = 0x706c61
39 40
)

41
var (
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
	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,
	}
Steven Allen's avatar
Steven Allen committed
58 59 60 61 62 63 64
	protoDNS = Protocol{
		Code:       P_DNS,
		Size:       LengthPrefixedVarSize,
		Name:       "dns",
		VCode:      CodeToVarint(P_DNS),
		Transcoder: TranscoderDns,
	}
godcong's avatar
godcong committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	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,
	}
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
	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,
	}
Marco Munizaga's avatar
Marco Munizaga committed
109 110 111 112 113 114 115
	protoIPCIDR = Protocol{
		Name:       "ipcidr",
		Code:       P_IPCIDR,
		VCode:      CodeToVarint(P_IPCIDR),
		Size:       8,
		Transcoder: TranscoderIPCIDR,
	}
116
	// these require varint
mwnx's avatar
mwnx committed
117 118 119 120 121 122 123 124
	protoIP6ZONE = Protocol{
		Name:       "ip6zone",
		Code:       P_IP6ZONE,
		VCode:      CodeToVarint(P_IP6ZONE),
		Size:       LengthPrefixedVarSize,
		Path:       false,
		Transcoder: TranscoderIP6Zone,
	}
125 126 127 128 129 130
	protoSCTP = Protocol{
		Name:       "sctp",
		Code:       P_SCTP,
		VCode:      CodeToVarint(P_SCTP),
		Size:       16,
		Transcoder: TranscoderPort,
131
	}
godcong's avatar
godcong committed
132 133 134 135 136 137 138 139

	protoCIRCUIT = Protocol{
		Code:  P_CIRCUIT,
		Size:  0,
		Name:  "p2p-circuit",
		VCode: CodeToVarint(P_CIRCUIT),
	}

idk's avatar
idk committed
140
	protoONION2 = Protocol{
141
		Name:       "onion",
142 143
		Code:       P_ONION,
		VCode:      CodeToVarint(P_ONION),
144 145
		Size:       96,
		Transcoder: TranscoderOnion,
146
	}
idk's avatar
idk committed
147 148 149 150 151 152 153
	protoONION3 = Protocol{
		Name:       "onion3",
		Code:       P_ONION3,
		VCode:      CodeToVarint(P_ONION3),
		Size:       296,
		Transcoder: TranscoderOnion3,
	}
154 155 156 157
	protoGARLIC64 = Protocol{
		Name:       "garlic64",
		Code:       P_GARLIC64,
		VCode:      CodeToVarint(P_GARLIC64),
idk's avatar
idk committed
158
		Size:       LengthPrefixedVarSize,
159
		Transcoder: TranscoderGarlic64,
idk's avatar
idk committed
160
	}
idk's avatar
idk committed
161 162 163 164 165 166 167
	protoGARLIC32 = Protocol{
		Name:       "garlic32",
		Code:       P_GARLIC32,
		VCode:      CodeToVarint(P_GARLIC32),
		Size:       LengthPrefixedVarSize,
		Transcoder: TranscoderGarlic32,
	}
168 169 170 171
	protoUTP = Protocol{
		Name:  "utp",
		Code:  P_UTP,
		VCode: CodeToVarint(P_UTP),
172
	}
173 174 175 176
	protoUDT = Protocol{
		Name:  "udt",
		Code:  P_UDT,
		VCode: CodeToVarint(P_UDT),
177
	}
178 179 180 181
	protoQUIC = Protocol{
		Name:  "quic",
		Code:  P_QUIC,
		VCode: CodeToVarint(P_QUIC),
182
	}
Marten Seemann's avatar
Marten Seemann committed
183 184 185 186 187
	protoWEBTRANSPORT = Protocol{
		Name:  "webtransport",
		Code:  P_WEBTRANSPORT,
		VCode: CodeToVarint(P_WEBTRANSPORT),
	}
Marten Seemann's avatar
Marten Seemann committed
188 189 190 191 192 193 194
	protoCERTHASH = Protocol{
		Name:       "certhash",
		Code:       P_CERTHASH,
		VCode:      CodeToVarint(P_CERTHASH),
		Size:       LengthPrefixedVarSize,
		Transcoder: TranscoderCertHash,
	}
195 196 197 198
	protoHTTP = Protocol{
		Name:  "http",
		Code:  P_HTTP,
		VCode: CodeToVarint(P_HTTP),
199
	}
200 201 202 203
	protoHTTPS = Protocol{
		Name:  "https",
		Code:  P_HTTPS,
		VCode: CodeToVarint(P_HTTPS),
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
204
	}
205
	protoP2P = Protocol{
206
		Name:       "p2p",
207 208 209 210
		Code:       P_P2P,
		VCode:      CodeToVarint(P_P2P),
		Size:       LengthPrefixedVarSize,
		Transcoder: TranscoderP2P,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
211
	}
212 213 214 215 216 217 218
	protoUNIX = Protocol{
		Name:       "unix",
		Code:       P_UNIX,
		VCode:      CodeToVarint(P_UNIX),
		Size:       LengthPrefixedVarSize,
		Path:       true,
		Transcoder: TranscoderUnix,
219
	}
backkem's avatar
backkem committed
220 221 222 223 224
	protoP2P_WEBRTC_DIRECT = Protocol{
		Name:  "p2p-webrtc-direct",
		Code:  P_P2P_WEBRTC_DIRECT,
		VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
	}
Pavel Karpy's avatar
Pavel Karpy committed
225 226 227 228
	protoTLS = Protocol{
		Name:  "tls",
		Code:  P_TLS,
		VCode: CodeToVarint(P_TLS),
Marten Seemann's avatar
Marten Seemann committed
229 230 231 232 233
	}
	protoNOISE = Protocol{
		Name:  "noise",
		Code:  P_NOISE,
		VCode: CodeToVarint(P_NOISE),
Pavel Karpy's avatar
Pavel Karpy committed
234
	}
235 236 237 238 239
	protoPlaintextV2 = Protocol{
		Name:  "plaintextv2",
		Code:  P_PLAINTEXTV2,
		VCode: CodeToVarint(P_PLAINTEXTV2),
	}
godcong's avatar
godcong committed
240 241 242 243 244
	protoWS = Protocol{
		Name:  "ws",
		Code:  P_WS,
		VCode: CodeToVarint(P_WS),
	}
Steven Allen's avatar
Steven Allen committed
245 246 247 248 249
	protoWSS = Protocol{
		Name:  "wss",
		Code:  P_WSS,
		VCode: CodeToVarint(P_WSS),
	}
250
)
251

252 253 254 255
func init() {
	for _, p := range []Protocol{
		protoIP4,
		protoTCP,
Steven Allen's avatar
Steven Allen committed
256
		protoDNS,
godcong's avatar
godcong committed
257 258 259
		protoDNS4,
		protoDNS6,
		protoDNSADDR,
260 261 262
		protoUDP,
		protoDCCP,
		protoIP6,
mwnx's avatar
mwnx committed
263
		protoIP6ZONE,
Marco Munizaga's avatar
Marco Munizaga committed
264
		protoIPCIDR,
265
		protoSCTP,
godcong's avatar
godcong committed
266
		protoCIRCUIT,
idk's avatar
idk committed
267 268
		protoONION2,
		protoONION3,
269
		protoGARLIC64,
idk's avatar
idk committed
270
		protoGARLIC32,
271 272 273
		protoUTP,
		protoUDT,
		protoQUIC,
Marten Seemann's avatar
Marten Seemann committed
274
		protoWEBTRANSPORT,
Marten Seemann's avatar
Marten Seemann committed
275
		protoCERTHASH,
276 277 278 279
		protoHTTP,
		protoHTTPS,
		protoP2P,
		protoUNIX,
backkem's avatar
backkem committed
280
		protoP2P_WEBRTC_DIRECT,
Pavel Karpy's avatar
Pavel Karpy committed
281
		protoTLS,
Marten Seemann's avatar
Marten Seemann committed
282
		protoNOISE,
godcong's avatar
godcong committed
283
		protoWS,
Steven Allen's avatar
Steven Allen committed
284
		protoWSS,
285
		protoPlaintextV2,
286 287 288 289
	} {
		if err := AddProtocol(p); err != nil {
			panic(err)
		}
290
	}
291 292 293 294

	// explicitly set both of these
	protocolsByName["p2p"] = protoP2P
	protocolsByName["ipfs"] = protoP2P
295
}