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

3 4 5 6 7
// You **MUST** register your multicodecs with
// https://github.com/multiformats/multicodec before adding them here.
//
// TODO: Use a single source of truth for all multicodecs instead of
// distributing them like this...
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
8
const (
mwnx's avatar
mwnx committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
	P_IP4     = 0x0004
	P_TCP     = 0x0006
	P_UDP     = 0x0111
	P_DCCP    = 0x0021
	P_IP6     = 0x0029
	P_IP6ZONE = 0x002A
	P_QUIC    = 0x01CC
	P_SCTP    = 0x0084
	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
25 26
)

27
var (
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
	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,
	}
	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,
	}
67
	// these require varint
mwnx's avatar
mwnx committed
68 69 70 71 72 73 74 75
	protoIP6ZONE = Protocol{
		Name:       "ip6zone",
		Code:       P_IP6ZONE,
		VCode:      CodeToVarint(P_IP6ZONE),
		Size:       LengthPrefixedVarSize,
		Path:       false,
		Transcoder: TranscoderIP6Zone,
	}
76 77 78 79 80 81
	protoSCTP = Protocol{
		Name:       "sctp",
		Code:       P_SCTP,
		VCode:      CodeToVarint(P_SCTP),
		Size:       16,
		Transcoder: TranscoderPort,
82
	}
83 84 85 86 87 88
	protoONION = Protocol{
		Name:       "onion",
		Code:       P_ONION,
		VCode:      CodeToVarint(P_ONION),
		Size:       96,
		Transcoder: TranscoderOnion,
89
	}
90 91 92 93
	protoUTP = Protocol{
		Name:  "utp",
		Code:  P_UTP,
		VCode: CodeToVarint(P_UTP),
94
	}
95 96 97 98
	protoUDT = Protocol{
		Name:  "udt",
		Code:  P_UDT,
		VCode: CodeToVarint(P_UDT),
99
	}
100 101 102 103
	protoQUIC = Protocol{
		Name:  "quic",
		Code:  P_QUIC,
		VCode: CodeToVarint(P_QUIC),
104
	}
105 106 107 108
	protoHTTP = Protocol{
		Name:  "http",
		Code:  P_HTTP,
		VCode: CodeToVarint(P_HTTP),
109
	}
110 111 112 113
	protoHTTPS = Protocol{
		Name:  "https",
		Code:  P_HTTPS,
		VCode: CodeToVarint(P_HTTPS),
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
114
	}
115 116 117 118 119 120
	protoP2P = Protocol{
		Name:       "ipfs",
		Code:       P_P2P,
		VCode:      CodeToVarint(P_P2P),
		Size:       LengthPrefixedVarSize,
		Transcoder: TranscoderP2P,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
121
	}
122 123 124 125 126 127 128
	protoUNIX = Protocol{
		Name:       "unix",
		Code:       P_UNIX,
		VCode:      CodeToVarint(P_UNIX),
		Size:       LengthPrefixedVarSize,
		Path:       true,
		Transcoder: TranscoderUnix,
129
	}
130
)
131

132 133 134 135 136 137 138
func init() {
	for _, p := range []Protocol{
		protoIP4,
		protoTCP,
		protoUDP,
		protoDCCP,
		protoIP6,
mwnx's avatar
mwnx committed
139
		protoIP6ZONE,
140 141 142 143 144 145 146 147 148 149 150 151 152
		protoSCTP,
		protoONION,
		protoUTP,
		protoUDT,
		protoQUIC,
		protoHTTP,
		protoHTTPS,
		protoP2P,
		protoUNIX,
	} {
		if err := AddProtocol(p); err != nil {
			panic(err)
		}
153
	}
154 155 156 157

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