mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-27 21:37:57 +08:00
handshake1 renaming
This commit is contained in:
parent
cc5c181ae0
commit
97c66ddc8f
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
handshake "github.com/jbenet/go-ipfs/net/handshake"
|
||||
hspb "github.com/jbenet/go-ipfs/net/handshake/pb"
|
||||
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
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 {
|
||||
rpeer := c.RemotePeer()
|
||||
lpeer := c.LocalPeer()
|
||||
|
||||
var remoteH, localH *handshake.Handshake1
|
||||
localH = handshake.CurrentHandshake()
|
||||
var remoteH, localH *hspb.Handshake1
|
||||
localH = handshake.Handshake1Msg()
|
||||
|
||||
myVerBytes, err := proto.Marshal(localH)
|
||||
if err != nil {
|
||||
@ -39,7 +40,7 @@ func VersionHandshake(ctx context.Context, c Conn) error {
|
||||
return fmt.Errorf("error retrieving from conn: %v", rpeer)
|
||||
}
|
||||
|
||||
remoteH = new(handshake.Handshake1)
|
||||
remoteH = new(hspb.Handshake1)
|
||||
err = proto.Unmarshal(data, remoteH)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not decode remote version: %q", err)
|
||||
@ -48,7 +49,7 @@ func VersionHandshake(ctx context.Context, c Conn) error {
|
||||
log.Debug("Received remote version (%s) from %s", remoteH, rpeer)
|
||||
}
|
||||
|
||||
if err := handshake.Compatible(localH, remoteH); err != nil {
|
||||
if err := handshake.Handshake1Compatible(localH, remoteH); err != nil {
|
||||
log.Info("%s (%s) incompatible version with %s (%s)", lpeer, localH, rpeer, remoteH)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
|
||||
all: semver.pb.go
|
||||
|
||||
semver.pb.go: semver.proto
|
||||
protoc --gogo_out=. --proto_path=../../../../../:/usr/local/opt/protobuf/include:. $<
|
||||
|
||||
clean:
|
||||
rm semver.pb.go
|
||||
@ -4,33 +4,35 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
pb "github.com/jbenet/go-ipfs/net/handshake/pb"
|
||||
updates "github.com/jbenet/go-ipfs/updates"
|
||||
|
||||
semver "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
|
||||
)
|
||||
|
||||
// currentVersion holds the current protocol version for a client running this code
|
||||
var currentVersion *semver.Version
|
||||
// ipfsVersion holds the current protocol version for a client running this code
|
||||
var ipfsVersion *semver.Version
|
||||
var clientVersion = "go-ipfs/" + updates.Version
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
currentVersion, err = semver.NewVersion("0.0.1")
|
||||
ipfsVersion, err = semver.NewVersion("0.0.1")
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("invalid protocol version: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// CurrentHandshake returns the current protocol version as a protobuf message
|
||||
func CurrentHandshake() *Handshake1 {
|
||||
return NewHandshake1(currentVersion.String(), "go-ipfs/"+updates.Version)
|
||||
// Handshake1Msg returns the current protocol version as a protobuf message
|
||||
func Handshake1Msg() *pb.Handshake1 {
|
||||
return NewHandshake1(ipfsVersion.String(), clientVersion)
|
||||
}
|
||||
|
||||
// ErrVersionMismatch is returned when two clients don't share a protocol version
|
||||
var ErrVersionMismatch = errors.New("protocol missmatch")
|
||||
|
||||
// Compatible checks wether two versions are compatible
|
||||
// Handshake1Compatible checks wether two versions are compatible
|
||||
// returns nil if they are fine
|
||||
func Compatible(handshakeA, handshakeB *Handshake1) error {
|
||||
func Handshake1Compatible(handshakeA, handshakeB *pb.Handshake1) error {
|
||||
a, err := semver.NewVersion(*handshakeA.ProtocolVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -48,8 +50,8 @@ func Compatible(handshakeA, handshakeB *Handshake1) error {
|
||||
}
|
||||
|
||||
// NewHandshake1 creates a new Handshake1 from the two strings
|
||||
func NewHandshake1(protoVer, agentVer string) *Handshake1 {
|
||||
return &Handshake1{
|
||||
func NewHandshake1(protoVer, agentVer string) *pb.Handshake1 {
|
||||
return &pb.Handshake1{
|
||||
ProtocolVersion: &protoVer,
|
||||
AgentVersion: &agentVer,
|
||||
}
|
||||
@ -2,7 +2,7 @@ package handshake
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCompatible(t *testing.T) {
|
||||
func TestH1Compatible(t *testing.T) {
|
||||
tcases := []struct {
|
||||
a, b string
|
||||
expected error
|
||||
@ -16,7 +16,7 @@ func TestCompatible(t *testing.T) {
|
||||
|
||||
for i, tcase := range tcases {
|
||||
|
||||
if Compatible(NewHandshake1(tcase.a, ""), NewHandshake1(tcase.b, "")) != tcase.expected {
|
||||
if Handshake1Compatible(NewHandshake1(tcase.a, ""), NewHandshake1(tcase.b, "")) != tcase.expected {
|
||||
t.Fatalf("case[%d] failed", i)
|
||||
}
|
||||
}
|
||||
11
net/handshake/pb/Makefile
Normal file
11
net/handshake/pb/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
PB = $(wildcard *.proto)
|
||||
GO = $(PB:.proto=.pb.go)
|
||||
|
||||
all: $(GO)
|
||||
|
||||
%.pb.go: %.proto
|
||||
protoc --gogo_out=. --proto_path=../../../../../../:/usr/local/opt/protobuf/include:. $<
|
||||
|
||||
clean:
|
||||
rm *.pb.go
|
||||
@ -1,25 +1,31 @@
|
||||
// Code generated by protoc-gen-gogo.
|
||||
// source: semver.proto
|
||||
// source: handshake.proto
|
||||
// DO NOT EDIT!
|
||||
|
||||
/*
|
||||
Package handshake is a generated protocol buffer package.
|
||||
Package handshake_pb is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
semver.proto
|
||||
handshake.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Handshake1
|
||||
Handshake3
|
||||
*/
|
||||
package handshake
|
||||
package handshake_pb
|
||||
|
||||
import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
|
||||
import proto "code.google.com/p/gogoprotobuf/proto"
|
||||
import json "encoding/json"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
// discarding unused import mux "github.com/jbenet/go-ipfs/net/mux/mux.pb"
|
||||
|
||||
// Reference proto, json, and math imports to suppress error if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = &json.SyntaxError{}
|
||||
var _ = math.Inf
|
||||
|
||||
// Handshake1 is delivered _before_ the secure channel is initialized
|
||||
type Handshake1 struct {
|
||||
// protocolVersion determines compatibility between peers
|
||||
ProtocolVersion *string `protobuf:"bytes,1,opt,name=protocolVersion" json:"protocolVersion,omitempty"`
|
||||
@ -47,5 +53,23 @@ func (m *Handshake1) GetAgentVersion() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Handshake3 is delivered _after_ the secure channel is initialized
|
||||
type Handshake3 struct {
|
||||
// listenAddrs are the multiaddrs this node listens for open connections on
|
||||
ListenAddrs [][]byte `protobuf:"bytes,2,rep,name=listenAddrs" json:"listenAddrs,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Handshake3) Reset() { *m = Handshake3{} }
|
||||
func (m *Handshake3) String() string { return proto.CompactTextString(m) }
|
||||
func (*Handshake3) ProtoMessage() {}
|
||||
|
||||
func (m *Handshake3) GetListenAddrs() [][]byte {
|
||||
if m != nil {
|
||||
return m.ListenAddrs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
}
|
||||
33
net/handshake/pb/handshake.proto
Normal file
33
net/handshake/pb/handshake.proto
Normal file
@ -0,0 +1,33 @@
|
||||
package handshake.pb;
|
||||
|
||||
import "github.com/jbenet/go-ipfs/net/mux/mux.proto";
|
||||
|
||||
// Handshake1 is delivered _before_ the secure channel is initialized
|
||||
message Handshake1 {
|
||||
// protocolVersion determines compatibility between peers
|
||||
optional string protocolVersion = 1; // semver
|
||||
|
||||
// agentVersion is like a UserAgent string in browsers, or client version in bittorrent
|
||||
// includes the client name and client. e.g. "go-ipfs/0.1.0"
|
||||
optional string agentVersion = 2; // semver
|
||||
|
||||
// we'll have more fields here later.
|
||||
}
|
||||
|
||||
// Handshake3 is delivered _after_ the secure channel is initialized
|
||||
message Handshake3 {
|
||||
|
||||
// publicKey is this node's public key (which also gives its node.ID)
|
||||
// - may not need to be sent, as secure channel implies it has been sent.
|
||||
// - then again, if we change / disable secure channel, may still want it.
|
||||
// optional bytes publicKey = 1;
|
||||
|
||||
// listenAddrs are the multiaddrs this node listens for open connections on
|
||||
repeated bytes listenAddrs = 2;
|
||||
|
||||
// TODO
|
||||
// services list the services this node is running
|
||||
// repeated mux.ProtocolID services = 3;
|
||||
|
||||
// we'll have more fields here later.
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package handshake;
|
||||
|
||||
message Handshake1 {
|
||||
// protocolVersion determines compatibility between peers
|
||||
optional string protocolVersion = 1; // semver
|
||||
|
||||
// agentVersion is like a UserAgent string in browsers, or client version in bittorrent
|
||||
// includes the client name and client. e.g. "go-ipfs/0.1.0"
|
||||
optional string agentVersion = 2; // semver
|
||||
|
||||
// we'll have more fields here later.
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user