handshake1 renaming
Juan Batiz-Benet committed
Oct 22, 2014 at 04:56 UTC
97c66ddc8f2047e04a15e3f4abbdfbe2ee92c9e1
8 files changed
+93
-42
net/conn/handshake.go
+5
-4
@@ -5,6 +5,7 @@ import (
5
"fmt"
6
7
handshake "github.com/jbenet/go-ipfs/net/handshake"
8
+ hspb "github.com/jbenet/go-ipfs/net/handshake/pb"
9
10
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
11
proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
@@ -16,8 +17,8 @@ func VersionHandshake(ctx context.Context, c Conn) error {
17
rpeer := c.RemotePeer()
18
lpeer := c.LocalPeer()
19
19
- var remoteH, localH *handshake.Handshake1
20
- localH = handshake.CurrentHandshake()
20
+ var remoteH, localH *hspb.Handshake1
21
+ localH = handshake.Handshake1Msg()
22
23
myVerBytes, err := proto.Marshal(localH)
24
if err != nil {
@@ -39,7 +40,7 @@ func VersionHandshake(ctx context.Context, c Conn) error {
40
return fmt.Errorf("error retrieving from conn: %v", rpeer)
41
}
42
42
- remoteH = new(handshake.Handshake1)
43
+ remoteH = new(hspb.Handshake1)
44
err = proto.Unmarshal(data, remoteH)
45
if err != nil {
46
return fmt.Errorf("could not decode remote version: %q", err)
@@ -48,7 +49,7 @@ func VersionHandshake(ctx context.Context, c Conn) error {
49
log.Debug("Received remote version (%s) from %s", remoteH, rpeer)
50
}
51
51
- if err := handshake.Compatible(localH, remoteH); err != nil {
52
+ if err := handshake.Handshake1Compatible(localH, remoteH); err != nil {
53
log.Info("%s (%s) incompatible version with %s (%s)", lpeer, localH, rpeer, remoteH)
54
return err
55
}
net/handshake/Makefile
deleted
-8
@@ -1,8 +0,0 @@
1
-
2
-all: semver.pb.go
3
-
4
-semver.pb.go: semver.proto
5
- protoc --gogo_out=. --proto_path=../../../../../:/usr/local/opt/protobuf/include:. $<
6
-
7
-clean:
8
- rm semver.pb.go
net/handshake/handshake1.go
renamed
+12
-10
@@ -4,33 +4,35 @@ import (
4
"errors"
5
"fmt"
6
7
+ pb "github.com/jbenet/go-ipfs/net/handshake/pb"
8
updates "github.com/jbenet/go-ipfs/updates"
9
10
semver "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
11
)
12
12
-// currentVersion holds the current protocol version for a client running this code
13
-var currentVersion *semver.Version
13
+// ipfsVersion holds the current protocol version for a client running this code
14
+var ipfsVersion *semver.Version
15
+var clientVersion = "go-ipfs/" + updates.Version
16
17
func init() {
18
var err error
17
- currentVersion, err = semver.NewVersion("0.0.1")
19
+ ipfsVersion, err = semver.NewVersion("0.0.1")
20
if err != nil {
21
panic(fmt.Errorf("invalid protocol version: %v", err))
22
}
23
}
24
23
-// CurrentHandshake returns the current protocol version as a protobuf message
24
-func CurrentHandshake() *Handshake1 {
25
- return NewHandshake1(currentVersion.String(), "go-ipfs/"+updates.Version)
25
+// Handshake1Msg returns the current protocol version as a protobuf message
26
+func Handshake1Msg() *pb.Handshake1 {
27
+ return NewHandshake1(ipfsVersion.String(), clientVersion)
28
}
29
30
// ErrVersionMismatch is returned when two clients don't share a protocol version
31
var ErrVersionMismatch = errors.New("protocol missmatch")
32
31
-// Compatible checks wether two versions are compatible
33
+// Handshake1Compatible checks wether two versions are compatible
34
// returns nil if they are fine
33
-func Compatible(handshakeA, handshakeB *Handshake1) error {
35
+func Handshake1Compatible(handshakeA, handshakeB *pb.Handshake1) error {
36
a, err := semver.NewVersion(*handshakeA.ProtocolVersion)
37
if err != nil {
38
return err
@@ -48,8 +50,8 @@ func Compatible(handshakeA, handshakeB *Handshake1) error {
50
}
51
52
// NewHandshake1 creates a new Handshake1 from the two strings
51
-func NewHandshake1(protoVer, agentVer string) *Handshake1 {
52
- return &Handshake1{
53
+func NewHandshake1(protoVer, agentVer string) *pb.Handshake1 {
54
+ return &pb.Handshake1{
55
ProtocolVersion: &protoVer,
56
AgentVersion: &agentVer,
57
}
net/handshake/handshake1_test.go
renamed
+2
-2
@@ -2,7 +2,7 @@ package handshake
2
3
import "testing"
4
5
-func TestCompatible(t *testing.T) {
5
+func TestH1Compatible(t *testing.T) {
6
tcases := []struct {
7
a, b string
8
expected error
@@ -16,7 +16,7 @@ func TestCompatible(t *testing.T) {
16
17
for i, tcase := range tcases {
18
19
- if Compatible(NewHandshake1(tcase.a, ""), NewHandshake1(tcase.b, "")) != tcase.expected {
19
+ if Handshake1Compatible(NewHandshake1(tcase.a, ""), NewHandshake1(tcase.b, "")) != tcase.expected {
20
t.Fatalf("case[%d] failed", i)
21
}
22
}
net/handshake/pb/Makefile
new
+11
@@ -0,0 +1,11 @@
1
+
2
+PB = $(wildcard *.proto)
3
+GO = $(PB:.proto=.pb.go)
4
+
5
+all: $(GO)
6
+
7
+%.pb.go: %.proto
8
+ protoc --gogo_out=. --proto_path=../../../../../../:/usr/local/opt/protobuf/include:. $<
9
+
10
+clean:
11
+ rm *.pb.go
net/handshake/pb/handshake.pb.go
renamed
+30
-6
@@ -1,25 +1,31 @@
1
// Code generated by protoc-gen-gogo.
2
-// source: semver.proto
2
+// source: handshake.proto
3
// DO NOT EDIT!
4
5
/*
6
-Package handshake is a generated protocol buffer package.
6
+Package handshake_pb is a generated protocol buffer package.
7
8
It is generated from these files:
9
- semver.proto
9
+ handshake.proto
10
11
It has these top-level messages:
12
Handshake1
13
+ Handshake3
14
*/
14
-package handshake
15
+package handshake_pb
16
16
-import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
17
+import proto "code.google.com/p/gogoprotobuf/proto"
18
+import json "encoding/json"
19
import math "math"
20
19
-// Reference imports to suppress errors if they are not otherwise used.
21
+// discarding unused import mux "github.com/jbenet/go-ipfs/net/mux/mux.pb"
22
+
23
+// Reference proto, json, and math imports to suppress error if they are not otherwise used.
24
var _ = proto.Marshal
25
+var _ = &json.SyntaxError{}
26
var _ = math.Inf
27
28
+// Handshake1 is delivered _before_ the secure channel is initialized
29
type Handshake1 struct {
30
// protocolVersion determines compatibility between peers
31
ProtocolVersion *string `protobuf:"bytes,1,opt,name=protocolVersion" json:"protocolVersion,omitempty"`
@@ -47,5 +53,23 @@ func (m *Handshake1) GetAgentVersion() string {
53
return ""
54
}
55
56
+// Handshake3 is delivered _after_ the secure channel is initialized
57
+type Handshake3 struct {
58
+ // listenAddrs are the multiaddrs this node listens for open connections on
59
+ ListenAddrs [][]byte `protobuf:"bytes,2,rep,name=listenAddrs" json:"listenAddrs,omitempty"`
60
+ XXX_unrecognized []byte `json:"-"`
61
+}
62
+
63
+func (m *Handshake3) Reset() { *m = Handshake3{} }
64
+func (m *Handshake3) String() string { return proto.CompactTextString(m) }
65
+func (*Handshake3) ProtoMessage() {}
66
+
67
+func (m *Handshake3) GetListenAddrs() [][]byte {
68
+ if m != nil {
69
+ return m.ListenAddrs
70
+ }
71
+ return nil
72
+}
73
+
74
func init() {
75
}
net/handshake/pb/handshake.proto
new
+33
@@ -0,0 +1,33 @@
1
+package handshake.pb;
2
+
3
+import "github.com/jbenet/go-ipfs/net/mux/mux.proto";
4
+
5
+// Handshake1 is delivered _before_ the secure channel is initialized
6
+message Handshake1 {
7
+ // protocolVersion determines compatibility between peers
8
+ optional string protocolVersion = 1; // semver
9
+
10
+ // agentVersion is like a UserAgent string in browsers, or client version in bittorrent
11
+ // includes the client name and client. e.g. "go-ipfs/0.1.0"
12
+ optional string agentVersion = 2; // semver
13
+
14
+ // we'll have more fields here later.
15
+}
16
+
17
+// Handshake3 is delivered _after_ the secure channel is initialized
18
+message Handshake3 {
19
+
20
+ // publicKey is this node's public key (which also gives its node.ID)
21
+ // - may not need to be sent, as secure channel implies it has been sent.
22
+ // - then again, if we change / disable secure channel, may still want it.
23
+ // optional bytes publicKey = 1;
24
+
25
+ // listenAddrs are the multiaddrs this node listens for open connections on
26
+ repeated bytes listenAddrs = 2;
27
+
28
+ // TODO
29
+ // services list the services this node is running
30
+ // repeated mux.ProtocolID services = 3;
31
+
32
+ // we'll have more fields here later.
33
+}
net/handshake/semver.proto
deleted
-12
@@ -1,12 +0,0 @@
1
-package handshake;
2
-
3
-message Handshake1 {
4
- // protocolVersion determines compatibility between peers
5
- optional string protocolVersion = 1; // semver
6
-
7
- // agentVersion is like a UserAgent string in browsers, or client version in bittorrent
8
- // includes the client name and client. e.g. "go-ipfs/0.1.0"
9
- optional string agentVersion = 2; // semver
10
-
11
- // we'll have more fields here later.
12
-}