mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-02 13:03:11 +00:00
move dns protocol definitions (3974bf3f84/dns.go (L11))
This commit is contained in:
parent
0550a5ba36
commit
bbcf5cbbc5
27
protocols.go
27
protocols.go
@ -5,6 +5,9 @@ package multiaddr
|
||||
const (
|
||||
P_IP4 = 0x0004
|
||||
P_TCP = 0x0006
|
||||
P_DNS4 = 0x0036
|
||||
P_DNS6 = 0x0037
|
||||
P_DNSADDR = 0x0038
|
||||
P_UDP = 0x0111
|
||||
P_DCCP = 0x0021
|
||||
P_IP6 = 0x0029
|
||||
@ -44,6 +47,27 @@ var (
|
||||
Path: false,
|
||||
Transcoder: TranscoderPort,
|
||||
}
|
||||
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,
|
||||
}
|
||||
protoUDP = Protocol{
|
||||
Name: "udp",
|
||||
Code: P_UDP,
|
||||
@ -175,6 +199,9 @@ func init() {
|
||||
for _, p := range []Protocol{
|
||||
protoIP4,
|
||||
protoTCP,
|
||||
protoDNS4,
|
||||
protoDNS6,
|
||||
protoDNSADDR,
|
||||
protoUDP,
|
||||
protoDCCP,
|
||||
protoIP6,
|
||||
|
||||
@ -317,3 +317,20 @@ func unixStB(s string) ([]byte, error) {
|
||||
func unixBtS(b []byte) (string, error) {
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
var TranscoderDns = NewTranscoderFromFunctions(dnsStB, dnsBtS, dnsVal)
|
||||
|
||||
func dnsVal(b []byte) error {
|
||||
if bytes.IndexByte(b, '/') >= 0 {
|
||||
return fmt.Errorf("domain name %q contains a slash", string(b))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func dnsStB(s string) ([]byte, error) {
|
||||
return []byte(s), nil
|
||||
}
|
||||
|
||||
func dnsBtS(b []byte) (string, error) {
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user