protocols.go 5.04 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
godcong's avatar
godcong committed
8 9 10
	P_DNS4              = 0x0036
	P_DNS6              = 0x0037
	P_DNSADDR           = 0x0038
backkem's avatar
backkem committed
11 12 13 14 15 16
	P_UDP               = 0x0111
	P_DCCP              = 0x0021
	P_IP6               = 0x0029
	P_IP6ZONE           = 0x002A
	P_QUIC              = 0x01CC
	P_SCTP              = 0x0084
godcong's avatar
godcong committed
17
	P_CIRCUIT           = 0x0122
backkem's avatar
backkem committed
18 19 20 21 22 23 24 25 26
	P_UDT               = 0x012D
	P_UTP               = 0x012E
	P_UNIX              = 0x0190
	P_P2P               = 0x01A5
	P_IPFS              = 0x01A5 // alias for backwards compatability
	P_HTTP              = 0x01E0
	P_HTTPS             = 0x01BB
	P_ONION             = 0x01BC // also for backwards compatibility
	P_ONION3            = 0x01BD
27 28
	P_GARLIC64          = 0x01BE
	P_GARLIC32          = 0x01BF
backkem's avatar
backkem committed
29
	P_P2P_WEBRTC_DIRECT = 0x0114
godcong's avatar
godcong committed
30
	P_WS                = 0x01DD
31 32
)

33
var (
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	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,
	}
godcong's avatar
godcong committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
	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,
	}
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	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,
	}
94
	// these require varint
mwnx's avatar
mwnx committed
95 96 97 98 99 100 101 102
	protoIP6ZONE = Protocol{
		Name:       "ip6zone",
		Code:       P_IP6ZONE,
		VCode:      CodeToVarint(P_IP6ZONE),
		Size:       LengthPrefixedVarSize,
		Path:       false,
		Transcoder: TranscoderIP6Zone,
	}
103 104 105 106 107 108
	protoSCTP = Protocol{
		Name:       "sctp",
		Code:       P_SCTP,
		VCode:      CodeToVarint(P_SCTP),
		Size:       16,
		Transcoder: TranscoderPort,
109
	}
godcong's avatar
godcong committed
110 111 112 113 114 115 116 117

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

idk's avatar
idk committed
118
	protoONION2 = Protocol{
119
		Name:       "onion",
120 121
		Code:       P_ONION,
		VCode:      CodeToVarint(P_ONION),
122 123
		Size:       96,
		Transcoder: TranscoderOnion,
124
	}
idk's avatar
idk committed
125 126 127 128 129 130 131
	protoONION3 = Protocol{
		Name:       "onion3",
		Code:       P_ONION3,
		VCode:      CodeToVarint(P_ONION3),
		Size:       296,
		Transcoder: TranscoderOnion3,
	}
132 133 134 135
	protoGARLIC64 = Protocol{
		Name:       "garlic64",
		Code:       P_GARLIC64,
		VCode:      CodeToVarint(P_GARLIC64),
idk's avatar
idk committed
136
		Size:       LengthPrefixedVarSize,
137
		Transcoder: TranscoderGarlic64,
idk's avatar
idk committed
138
	}
idk's avatar
idk committed
139 140 141 142 143 144 145
	protoGARLIC32 = Protocol{
		Name:       "garlic32",
		Code:       P_GARLIC32,
		VCode:      CodeToVarint(P_GARLIC32),
		Size:       LengthPrefixedVarSize,
		Transcoder: TranscoderGarlic32,
	}
146 147 148 149
	protoUTP = Protocol{
		Name:  "utp",
		Code:  P_UTP,
		VCode: CodeToVarint(P_UTP),
150
	}
151 152 153 154
	protoUDT = Protocol{
		Name:  "udt",
		Code:  P_UDT,
		VCode: CodeToVarint(P_UDT),
155
	}
156 157 158 159
	protoQUIC = Protocol{
		Name:  "quic",
		Code:  P_QUIC,
		VCode: CodeToVarint(P_QUIC),
160
	}
161 162 163 164
	protoHTTP = Protocol{
		Name:  "http",
		Code:  P_HTTP,
		VCode: CodeToVarint(P_HTTP),
165
	}
166 167 168 169
	protoHTTPS = Protocol{
		Name:  "https",
		Code:  P_HTTPS,
		VCode: CodeToVarint(P_HTTPS),
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
170
	}
171 172 173 174 175 176
	protoP2P = Protocol{
		Name:       "ipfs",
		Code:       P_P2P,
		VCode:      CodeToVarint(P_P2P),
		Size:       LengthPrefixedVarSize,
		Transcoder: TranscoderP2P,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
177
	}
178 179 180 181 182 183 184
	protoUNIX = Protocol{
		Name:       "unix",
		Code:       P_UNIX,
		VCode:      CodeToVarint(P_UNIX),
		Size:       LengthPrefixedVarSize,
		Path:       true,
		Transcoder: TranscoderUnix,
185
	}
backkem's avatar
backkem committed
186 187 188 189 190
	protoP2P_WEBRTC_DIRECT = Protocol{
		Name:  "p2p-webrtc-direct",
		Code:  P_P2P_WEBRTC_DIRECT,
		VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
	}
godcong's avatar
godcong committed
191 192 193 194 195
	protoWS = Protocol{
		Name:  "ws",
		Code:  P_WS,
		VCode: CodeToVarint(P_WS),
	}
196
)
197

198 199 200 201
func init() {
	for _, p := range []Protocol{
		protoIP4,
		protoTCP,
godcong's avatar
godcong committed
202 203 204
		protoDNS4,
		protoDNS6,
		protoDNSADDR,
205 206 207
		protoUDP,
		protoDCCP,
		protoIP6,
mwnx's avatar
mwnx committed
208
		protoIP6ZONE,
209
		protoSCTP,
godcong's avatar
godcong committed
210
		protoCIRCUIT,
idk's avatar
idk committed
211 212
		protoONION2,
		protoONION3,
213
		protoGARLIC64,
idk's avatar
idk committed
214
		protoGARLIC32,
215 216 217 218 219 220 221
		protoUTP,
		protoUDT,
		protoQUIC,
		protoHTTP,
		protoHTTPS,
		protoP2P,
		protoUNIX,
backkem's avatar
backkem committed
222
		protoP2P_WEBRTC_DIRECT,
godcong's avatar
godcong committed
223
		protoWS,
224 225 226 227
	} {
		if err := AddProtocol(p); err != nil {
			panic(err)
		}
228
	}
229 230 231 232

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