Skip to content

Commit

Permalink
Merge pull request #18 from multiformats/fix/global-multiaddr-registry
Browse files Browse the repository at this point in the history
fix: move multiaddr definitions to the multiaddr library
  • Loading branch information
Stebalien authored Sep 19, 2019
2 parents 3974bf3 + 4c5d47a commit fc9a9ea
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 87 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ os:
language: go

go:
- 1.11.x
- 1.12.x

env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gx
- BUILD_DEPTYPE=gomod


Expand All @@ -24,7 +23,6 @@ script:

cache:
directories:
- $GOPATH/src/gx
- $GOPATH/pkg/mod
- /home/travis/.cache/go-build

Expand Down
69 changes: 12 additions & 57 deletions dns.go
Original file line number Diff line number Diff line change
@@ -1,69 +1,24 @@
package madns

import (
"bytes"
"fmt"

ma "github.com/multiformats/go-multiaddr"
)

// Extracted from source of truth for multicodec codes: https://github.com/multiformats/multicodec
const (
P_DNS4 = 0x0036
P_DNS6 = 0x0037
P_DNSADDR = 0x0038
// Deprecated: use ma.P_DNS4
P_DNS4 = ma.P_DNS4
// Deprecated: use ma.P_DNS6
P_DNS6 = ma.P_DNS6
// Deprecated: use ma.P_DNSADDR
P_DNSADDR = ma.P_DNSADDR
)

var Dns4Protocol = ma.Protocol{
Code: P_DNS4,
Size: ma.LengthPrefixedVarSize,
Name: "dns4",
VCode: ma.CodeToVarint(P_DNS4),
Transcoder: DnsTranscoder,
}
var Dns6Protocol = ma.Protocol{
Code: P_DNS6,
Size: ma.LengthPrefixedVarSize,
Name: "dns6",
VCode: ma.CodeToVarint(P_DNS6),
Transcoder: DnsTranscoder,
}
var DnsaddrProtocol = ma.Protocol{
Code: P_DNSADDR,
Size: ma.LengthPrefixedVarSize,
Name: "dnsaddr",
VCode: ma.CodeToVarint(P_DNSADDR),
Transcoder: DnsTranscoder,
}

func init() {
err := ma.AddProtocol(Dns4Protocol)
if err != nil {
panic(fmt.Errorf("error registering dns4 protocol: %s", err))
}
err = ma.AddProtocol(Dns6Protocol)
if err != nil {
panic(fmt.Errorf("error registering dns6 protocol: %s", err))
}
err = ma.AddProtocol(DnsaddrProtocol)
if err != nil {
panic(fmt.Errorf("error registering dnsaddr protocol: %s", err))
}
}

var DnsTranscoder = ma.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
}
// Deprecated: use ma.ProtocolWithCode(P_DNS4)
var Dns4Protocol = ma.ProtocolWithCode(P_DNS4)

func dnsStB(s string) ([]byte, error) {
return []byte(s), nil
}
// Deprecated: use ma.ProtocolWithCode(P_DNS6)
var Dns6Protocol = ma.ProtocolWithCode(P_DNS6)

func dnsBtS(b []byte) (string, error) {
return string(b), nil
}
// Deprecated: use ma.ProtocolWithCode(P_DNSADDR)
var DnsaddrProtocol = ma.ProtocolWithCode(P_DNSADDR)
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/multiformats/go-multiaddr-dns

require github.com/multiformats/go-multiaddr v0.0.1
require github.com/multiformats/go-multiaddr v0.1.0

go 1.12
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XC
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/multiformats/go-multiaddr v0.0.1 h1:/QUV3VBMDI6pi6xfiw7lr6xhDWWvQKn9udPn68kLSdY=
github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44=
github.com/multiformats/go-multiaddr v0.1.0 h1:fkISCUNDb3xIpCcI6BGlPsQE+ywcxzimOsUnHWnrE74=
github.com/multiformats/go-multiaddr v0.1.0/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44=
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
Expand Down
24 changes: 0 additions & 24 deletions package.json

This file was deleted.

0 comments on commit fc9a9ea

Please sign in to comment.