protocols.go 6.72 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 (
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
	P_IP4               = 4
	P_TCP               = 6
	P_DNS               = 53 // 4 or 6
	P_DNS4              = 54
	P_DNS6              = 55
	P_DNSADDR           = 56
	P_UDP               = 273
	P_DCCP              = 33
	P_IP6               = 41
	P_IP6ZONE           = 42
	P_IPCIDR            = 43
	P_QUIC              = 460
	P_WEBTRANSPORT      = 465
	P_CERTHASH          = 466
	P_SCTP              = 132
	P_CIRCUIT           = 290
	P_UDT               = 301
	P_UTP               = 302
	P_UNIX              = 400
	P_P2P               = 421
	P_IPFS              = P_P2P // alias for backwards compatibility
	P_HTTP              = 480
	P_HTTPS             = 443 // deprecated alias for /tls/http
	P_ONION             = 444 // also for backwards compatibility
	P_ONION3            = 445
	P_GARLIC64          = 446
	P_GARLIC32          = 447
	P_P2P_WEBRTC_DIRECT = 276
	P_TLS               = 448
	P_SNI               = 449
	P_NOISE             = 454
	P_WS                = 477
	P_WSS               = 478 // deprecated alias for /tls/ws
	P_PLAINTEXTV2       = 7367777
	P_WEBRTC            = 280
41 42
)

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

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

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

266 267 268 269
func init() {
	for _, p := range []Protocol{
		protoIP4,
		protoTCP,
Steven Allen's avatar
Steven Allen committed
270
		protoDNS,
godcong's avatar
godcong committed
271 272 273
		protoDNS4,
		protoDNS6,
		protoDNSADDR,
274 275 276
		protoUDP,
		protoDCCP,
		protoIP6,
mwnx's avatar
mwnx committed
277
		protoIP6ZONE,
Marco Munizaga's avatar
Marco Munizaga committed
278
		protoIPCIDR,
279
		protoSCTP,
godcong's avatar
godcong committed
280
		protoCIRCUIT,
idk's avatar
idk committed
281 282
		protoONION2,
		protoONION3,
283
		protoGARLIC64,
idk's avatar
idk committed
284
		protoGARLIC32,
285 286 287
		protoUTP,
		protoUDT,
		protoQUIC,
Marten Seemann's avatar
Marten Seemann committed
288
		protoWEBTRANSPORT,
Marten Seemann's avatar
Marten Seemann committed
289
		protoCERTHASH,
290 291 292 293
		protoHTTP,
		protoHTTPS,
		protoP2P,
		protoUNIX,
backkem's avatar
backkem committed
294
		protoP2P_WEBRTC_DIRECT,
Pavel Karpy's avatar
Pavel Karpy committed
295
		protoTLS,
Marco Munizaga's avatar
Add SNI  
Marco Munizaga committed
296
		protoSNI,
Marten Seemann's avatar
Marten Seemann committed
297
		protoNOISE,
godcong's avatar
godcong committed
298
		protoWS,
Steven Allen's avatar
Steven Allen committed
299
		protoWSS,
300
		protoPlaintextV2,
Chinmay Kousik's avatar
Chinmay Kousik committed
301
		protoWebRTC,
302 303 304 305
	} {
		if err := AddProtocol(p); err != nil {
			panic(err)
		}
306
	}
307 308 309 310

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