Skip to content

Added support for onion addresses #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ var WebRTCDirect = Or(
And(HTTP, Base(ma.P_P2P_WEBRTC_DIRECT)),
And(HTTPS, Base(ma.P_P2P_WEBRTC_DIRECT)))

// Define a onion v2 format multiaddr
var ONION2 = Base(ma.P_ONION)

// Define a onion v3 format multiaddr
var ONION3 = Base(ma.P_ONION3)

// Define both onion v2 and v3 multiaddr
var ONION = Or(ONION2, ONION3)

const (
or = iota
and = iota
Expand Down
10 changes: 10 additions & 0 deletions patterns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ var TestVectors = map[string]*testVector{
Good: []string{"/ip4/1.2.3.4/https", "/dns4/example.io/https", "/dns6/::/tcp/7011/https", "/ip6/fc00::/https"},
Bad: []string{"/ip4/1.2.3.4/http", "/ip4/0.0.0.0/tcp/12345/quic", "/ip6/fc00::/tcp/5523"},
},
"ONION": {
Pattern: ONION,
Good: []string{"/onion/timaq4ygg2iegci7:1234", "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234"},
Bad: []string{"/onion/timaq4ygg2iegci:80", "/onion/timaq4ygg2iegci7:-1", "/onion/timaq4ygg2iegci7",
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopyyd:1234",
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:-1",
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd"},
},


}

func TestProtocolMatching(t *testing.T) {
Expand Down