Skip to content

Implemented byte decoder for onion addresses. Corrected onion bit size. #21

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

Merged
merged 1 commit into from
Sep 16, 2016
Merged
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
6 changes: 6 additions & 0 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ func addressBytesToString(p Protocol, b []byte) (string, error) {
return "", err
}
return m.B58String(), nil

case P_ONION:
addr := strings.ToLower(base32.StdEncoding.EncodeToString(b[0:10]))
port := binary.BigEndian.Uint16(b[10:12])
return addr + ":"+ strconv.Itoa(int(port)), nil

default:
return "", fmt.Errorf("unknown protocol")
}
Expand Down
3 changes: 2 additions & 1 deletion multiaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestBytesToString(t *testing.T) {

s2, err := bytesToString(b)
if err != nil {
t.Error("failed to convert", b)
t.Error("failed to convert", b, err)
}

if s1 != s2 {
Expand All @@ -177,6 +177,7 @@ func TestBytesToString(t *testing.T) {
testString("/ip4/127.0.0.1/udp/1234", "047f0000011104d2")
testString("/ip4/127.0.0.1/tcp/4321", "047f0000010610e1")
testString("/ip4/127.0.0.1/udp/1234/ip4/127.0.0.1/tcp/4321", "047f0000011104d2047f0000010610e1")
testString("/onion/aaimaq4ygg2iegci:80", "bc030010c0439831b48218480050")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the port? is it always strictly tcp? or is it an onion port? (meaning the transport is abstracted out)
If the client has to know the protocol, then I would imagine this being better: /onion/<hash>/tcp/80

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @david415 as he knows more about this than me. we were discussing elsewhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say separating out the port is better too, but I followed what the existing partial implementation was already doing. My understanding is that it is tcp.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • is it ALWAYS tcp? where can we get confirmation of this?
  • even if it IS always is TCP today, does it make sense to list it so that we can plug other transports in over tor? (sctp, quic, etc)
  • this is external-facing, right? the other side gets the port too?
  • if so, does this count as leaking identifying information? port numbers could be correlated. most onion sites are :80 (afaik), and port numbers are hard, but still. it is some info. not sure how much worse than response timing ...

could really use others' viewpoints on this. cc @david415 @leif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17:41 <•jbenet> ianopolous: if you need a decision now, i think the port should be layered.
17:42 <•jbenet> so "/tcp/<port>" not ":<tcp-port>"
17:42 <•jbenet> which -- now that i think about it -- may already be what's there now?

}

func TestBytesSplitAndJoin(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion protocols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ code size name
421 V ipfs
480 0 http
443 0 https
444 10 onion
444 96 onion
2 changes: 1 addition & 1 deletion protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var Protocols = []Protocol{
Protocol{P_IP6, 128, "ip6", CodeToVarint(P_IP6)},
// these require varint:
Protocol{P_SCTP, 16, "sctp", CodeToVarint(P_SCTP)},
Protocol{P_ONION, 80, "onion", CodeToVarint(P_ONION)},
Protocol{P_ONION, 96, "onion", CodeToVarint(P_ONION)},
Protocol{P_UTP, 0, "utp", CodeToVarint(P_UTP)},
Protocol{P_UDT, 0, "udt", CodeToVarint(P_UDT)},
Protocol{P_HTTP, 0, "http", CodeToVarint(P_HTTP)},
Expand Down