Commit 80ce35e6 authored by Pavle Batuta's avatar Pavle Batuta Committed by GitHub

Add welcome message to handshake (#312)

Co-authored-by: default avatarJanos Guljas <janos@resenje.org>
Co-authored-by: default avatareknir <rinkehendriksen@gmail.com>
parent 1ee1b179
...@@ -39,6 +39,7 @@ func (c *command) initStartCmd() (err error) { ...@@ -39,6 +39,7 @@ func (c *command) initStartCmd() (err error) {
optionNameDebugAPIAddr = "debug-api-addr" optionNameDebugAPIAddr = "debug-api-addr"
optionNameBootnodes = "bootnode" optionNameBootnodes = "bootnode"
optionNameNetworkID = "network-id" optionNameNetworkID = "network-id"
optionWelcomeMessage = "welcome-message"
optionCORSAllowedOrigins = "cors-allowed-origins" optionCORSAllowedOrigins = "cors-allowed-origins"
optionNameTracingEnabled = "tracing" optionNameTracingEnabled = "tracing"
optionNameTracingEndpoint = "tracing-endpoint" optionNameTracingEndpoint = "tracing-endpoint"
...@@ -121,6 +122,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz ...@@ -121,6 +122,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
DisableWS: c.config.GetBool(optionNameP2PDisableWS), DisableWS: c.config.GetBool(optionNameP2PDisableWS),
DisableQUIC: c.config.GetBool(optionNameP2PDisableQUIC), DisableQUIC: c.config.GetBool(optionNameP2PDisableQUIC),
NetworkID: c.config.GetUint64(optionNameNetworkID), NetworkID: c.config.GetUint64(optionNameNetworkID),
WelcomeMessage: c.config.GetString(optionWelcomeMessage),
Bootnodes: c.config.GetStringSlice(optionNameBootnodes), Bootnodes: c.config.GetStringSlice(optionNameBootnodes),
CORSAllowedOrigins: c.config.GetStringSlice(optionCORSAllowedOrigins), CORSAllowedOrigins: c.config.GetStringSlice(optionCORSAllowedOrigins),
TracingEnabled: c.config.GetBool(optionNameTracingEnabled), TracingEnabled: c.config.GetBool(optionNameTracingEnabled),
...@@ -189,6 +191,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz ...@@ -189,6 +191,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
cmd.Flags().String(optionNameTracingEndpoint, "127.0.0.1:6831", "endpoint to send tracing data") cmd.Flags().String(optionNameTracingEndpoint, "127.0.0.1:6831", "endpoint to send tracing data")
cmd.Flags().String(optionNameTracingServiceName, "bee", "service name identifier for tracing") cmd.Flags().String(optionNameTracingServiceName, "bee", "service name identifier for tracing")
cmd.Flags().String(optionNameVerbosity, "info", "log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace") cmd.Flags().String(optionNameVerbosity, "info", "log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace")
cmd.Flags().String(optionWelcomeMessage, "", "send a welcome message string during handshakes")
c.root.AddCommand(cmd) c.root.AddCommand(cmd)
return nil return nil
......
...@@ -77,6 +77,7 @@ type Options struct { ...@@ -77,6 +77,7 @@ type Options struct {
DisableWS bool DisableWS bool
DisableQUIC bool DisableQUIC bool
NetworkID uint64 NetworkID uint64
WelcomeMessage string
Bootnodes []string Bootnodes []string
CORSAllowedOrigins []string CORSAllowedOrigins []string
Logger logging.Logger Logger logging.Logger
...@@ -153,13 +154,14 @@ func NewBee(o Options) (*Bee, error) { ...@@ -153,13 +154,14 @@ func NewBee(o Options) (*Bee, error) {
signer := crypto.NewDefaultSigner(swarmPrivateKey) signer := crypto.NewDefaultSigner(swarmPrivateKey)
p2ps, err := libp2p.New(p2pCtx, signer, o.NetworkID, address, o.Addr, libp2p.Options{ p2ps, err := libp2p.New(p2pCtx, signer, o.NetworkID, address, o.Addr, libp2p.Options{
PrivateKey: libp2pPrivateKey, PrivateKey: libp2pPrivateKey,
NATAddr: o.NATAddr, NATAddr: o.NATAddr,
DisableWS: o.DisableWS, DisableWS: o.DisableWS,
DisableQUIC: o.DisableQUIC, DisableQUIC: o.DisableQUIC,
Addressbook: addressbook, Addressbook: addressbook,
Logger: logger, WelcomeMessage: o.WelcomeMessage,
Tracer: tracer, Logger: logger,
Tracer: tracer,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("p2p service: %w", err) return nil, fmt.Errorf("p2p service: %w", err)
......
...@@ -24,10 +24,15 @@ import ( ...@@ -24,10 +24,15 @@ import (
) )
const ( const (
ProtocolName = "handshake" // ProtocolName is the text of the name of the handshake protocol.
ProtocolName = "handshake"
// ProtocolVersion is the current handshake protocol version.
ProtocolVersion = "1.0.0" ProtocolVersion = "1.0.0"
StreamName = "handshake" // StreamName is the name of the stream used for handshake purposes.
messageTimeout = 5 * time.Second // maximum allowed time for a message to be read or written. StreamName = "handshake"
// MaxWelcomeMessageLength is maximum number of characters allowed in the welcome message.
MaxWelcomeMessageLength = 140
messageTimeout = 5 * time.Second
) )
var ( var (
...@@ -42,18 +47,24 @@ var ( ...@@ -42,18 +47,24 @@ var (
// ErrInvalidSyn is returned if observable address in ack is not a valid.. // ErrInvalidSyn is returned if observable address in ack is not a valid..
ErrInvalidSyn = errors.New("invalid syn") ErrInvalidSyn = errors.New("invalid syn")
// ErrWelcomeMessageLength is return if the welcome message is longer than the maximum length
ErrWelcomeMessageLength = fmt.Errorf("handshake welcome message longer than maximum of %d characters", MaxWelcomeMessageLength)
) )
// AdvertisableAddressResolver can Resolve a Multiaddress.
type AdvertisableAddressResolver interface { type AdvertisableAddressResolver interface {
Resolve(observedAdddress ma.Multiaddr) (ma.Multiaddr, error) Resolve(observedAdddress ma.Multiaddr) (ma.Multiaddr, error)
} }
// Service can perform initiate or handle a handshake between peers.
type Service struct { type Service struct {
signer crypto.Signer signer crypto.Signer
advertisableAddresser AdvertisableAddressResolver advertisableAddresser AdvertisableAddressResolver
overlay swarm.Address overlay swarm.Address
lightNode bool lightNode bool
networkID uint64 networkID uint64
welcomeMessage string
receivedHandshakes map[libp2ppeer.ID]struct{} receivedHandshakes map[libp2ppeer.ID]struct{}
receivedHandshakesMu sync.Mutex receivedHandshakesMu sync.Mutex
logger logging.Logger logger logging.Logger
...@@ -61,19 +72,32 @@ type Service struct { ...@@ -61,19 +72,32 @@ type Service struct {
network.Notifiee // handshake service can be the receiver for network.Notify network.Notifiee // handshake service can be the receiver for network.Notify
} }
func New(signer crypto.Signer, advertisableAddresser AdvertisableAddressResolver, overlay swarm.Address, networkID uint64, lighNode bool, logger logging.Logger) (*Service, error) { // Info contains the information received from the handshake.
type Info struct {
BzzAddress *bzz.Address
Light bool
}
// New creates a new handshake Service.
func New(signer crypto.Signer, advertisableAddresser AdvertisableAddressResolver, overlay swarm.Address, networkID uint64, lighNode bool, welcomeMessage string, logger logging.Logger) (*Service, error) {
if len(welcomeMessage) > MaxWelcomeMessageLength {
return nil, ErrWelcomeMessageLength
}
return &Service{ return &Service{
signer: signer, signer: signer,
advertisableAddresser: advertisableAddresser, advertisableAddresser: advertisableAddresser,
overlay: overlay, overlay: overlay,
networkID: networkID, networkID: networkID,
lightNode: lighNode, lightNode: lighNode,
welcomeMessage: welcomeMessage,
receivedHandshakes: make(map[libp2ppeer.ID]struct{}), receivedHandshakes: make(map[libp2ppeer.ID]struct{}),
logger: logger, logger: logger,
Notifiee: new(network.NoopNotifiee), Notifiee: new(network.NoopNotifiee),
}, nil }, nil
} }
// Handshake initiates a handshake with a peer.
func (s *Service) Handshake(stream p2p.Stream, peerMultiaddr ma.Multiaddr, peerID libp2ppeer.ID) (i *Info, err error) { func (s *Service) Handshake(stream p2p.Stream, peerMultiaddr ma.Multiaddr, peerID libp2ppeer.ID) (i *Info, err error) {
w, r := protobuf.NewWriterAndReader(stream) w, r := protobuf.NewWriterAndReader(stream)
fullRemoteMA, err := buildFullMA(peerMultiaddr, peerID) fullRemoteMA, err := buildFullMA(peerMultiaddr, peerID)
...@@ -128,19 +152,25 @@ func (s *Service) Handshake(stream p2p.Stream, peerMultiaddr ma.Multiaddr, peerI ...@@ -128,19 +152,25 @@ func (s *Service) Handshake(stream p2p.Stream, peerMultiaddr ma.Multiaddr, peerI
Overlay: bzzAddress.Overlay.Bytes(), Overlay: bzzAddress.Overlay.Bytes(),
Signature: bzzAddress.Signature, Signature: bzzAddress.Signature,
}, },
NetworkID: s.networkID, NetworkID: s.networkID,
Light: s.lightNode, Light: s.lightNode,
WelcomeMessage: s.welcomeMessage,
}); err != nil { }); err != nil {
return nil, fmt.Errorf("write ack message: %w", err) return nil, fmt.Errorf("write ack message: %w", err)
} }
s.logger.Tracef("handshake finished for peer (outbound) %s", remoteBzzAddress.Overlay.String()) s.logger.Tracef("handshake finished for peer (outbound) %s", remoteBzzAddress.Overlay.String())
if len(resp.Ack.WelcomeMessage) > 0 {
s.logger.Infof("greeting <%s> from peer: %s", resp.Ack.WelcomeMessage, remoteBzzAddress.Overlay.String())
}
return &Info{ return &Info{
BzzAddress: remoteBzzAddress, BzzAddress: remoteBzzAddress,
Light: resp.Ack.Light, Light: resp.Ack.Light,
}, nil }, nil
} }
// Handle handles an incoming handshake from a peer.
func (s *Service) Handle(stream p2p.Stream, remoteMultiaddr ma.Multiaddr, remotePeerID libp2ppeer.ID) (i *Info, err error) { func (s *Service) Handle(stream p2p.Stream, remoteMultiaddr ma.Multiaddr, remotePeerID libp2ppeer.ID) (i *Info, err error) {
s.receivedHandshakesMu.Lock() s.receivedHandshakesMu.Lock()
if _, exists := s.receivedHandshakes[remotePeerID]; exists { if _, exists := s.receivedHandshakes[remotePeerID]; exists {
...@@ -196,8 +226,9 @@ func (s *Service) Handle(stream p2p.Stream, remoteMultiaddr ma.Multiaddr, remote ...@@ -196,8 +226,9 @@ func (s *Service) Handle(stream p2p.Stream, remoteMultiaddr ma.Multiaddr, remote
Overlay: bzzAddress.Overlay.Bytes(), Overlay: bzzAddress.Overlay.Bytes(),
Signature: bzzAddress.Signature, Signature: bzzAddress.Signature,
}, },
NetworkID: s.networkID, NetworkID: s.networkID,
Light: s.lightNode, Light: s.lightNode,
WelcomeMessage: s.welcomeMessage,
}, },
}); err != nil { }); err != nil {
return nil, fmt.Errorf("write synack message: %w", err) return nil, fmt.Errorf("write synack message: %w", err)
...@@ -214,12 +245,14 @@ func (s *Service) Handle(stream p2p.Stream, remoteMultiaddr ma.Multiaddr, remote ...@@ -214,12 +245,14 @@ func (s *Service) Handle(stream p2p.Stream, remoteMultiaddr ma.Multiaddr, remote
} }
s.logger.Tracef("handshake finished for peer (inbound) %s", remoteBzzAddress.Overlay.String()) s.logger.Tracef("handshake finished for peer (inbound) %s", remoteBzzAddress.Overlay.String())
return &Info{ return &Info{
BzzAddress: remoteBzzAddress, BzzAddress: remoteBzzAddress,
Light: ack.Light, Light: ack.Light,
}, nil }, nil
} }
// Disconnected is called when the peer disconnects.
func (s *Service) Disconnected(_ network.Network, c network.Conn) { func (s *Service) Disconnected(_ network.Network, c network.Conn) {
s.receivedHandshakesMu.Lock() s.receivedHandshakesMu.Lock()
defer s.receivedHandshakesMu.Unlock() defer s.receivedHandshakesMu.Unlock()
...@@ -242,8 +275,3 @@ func (s *Service) parseCheckAck(ack *pb.Ack) (*bzz.Address, error) { ...@@ -242,8 +275,3 @@ func (s *Service) parseCheckAck(ack *pb.Ack) (*bzz.Address, error) {
return bzzAddress, nil return bzzAddress, nil
} }
type Info struct {
BzzAddress *bzz.Address
Light bool
}
...@@ -24,6 +24,10 @@ import ( ...@@ -24,6 +24,10 @@ import (
) )
func TestHandshake(t *testing.T) { func TestHandshake(t *testing.T) {
const (
testWelcomeMessage = "HelloWorld"
)
logger := logging.New(ioutil.Discard, 0) logger := logging.New(ioutil.Discard, 0)
networkID := uint64(3) networkID := uint64(3)
...@@ -87,7 +91,7 @@ func TestHandshake(t *testing.T) { ...@@ -87,7 +91,7 @@ func TestHandshake(t *testing.T) {
aaddresser := &AdvertisableAddresserMock{} aaddresser := &AdvertisableAddresserMock{}
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, testWelcomeMessage, logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -109,8 +113,9 @@ func TestHandshake(t *testing.T) { ...@@ -109,8 +113,9 @@ func TestHandshake(t *testing.T) {
Overlay: node2BzzAddress.Overlay.Bytes(), Overlay: node2BzzAddress.Overlay.Bytes(),
Signature: node2BzzAddress.Signature, Signature: node2BzzAddress.Signature,
}, },
NetworkID: networkID, NetworkID: networkID,
Light: false, Light: false,
WelcomeMessage: testWelcomeMessage,
}, },
}); err != nil { }); err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -144,6 +149,20 @@ func TestHandshake(t *testing.T) { ...@@ -144,6 +149,20 @@ func TestHandshake(t *testing.T) {
ack.Light != false { ack.Light != false {
t.Fatal("bad ack") t.Fatal("bad ack")
} }
if ack.WelcomeMessage != testWelcomeMessage {
t.Fatalf("Bad ack welcome message: want %s, got %s", testWelcomeMessage, ack.WelcomeMessage)
}
})
t.Run("Handshake - welcome message too long", func(t *testing.T) {
const LongMessage = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi consectetur urna ut lorem sollicitudin posuere. Donec sagittis laoreet sapien."
expectedErr := handshake.ErrWelcomeMessageLength
_, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, LongMessage, logger)
if err == nil || err.Error() != expectedErr.Error() {
t.Fatal("expected:", expectedErr, "got:", err)
}
}) })
t.Run("Handshake - Syn write error", func(t *testing.T) { t.Run("Handshake - Syn write error", func(t *testing.T) {
...@@ -325,7 +344,7 @@ func TestHandshake(t *testing.T) { ...@@ -325,7 +344,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - OK", func(t *testing.T) { t.Run("Handle - OK", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -382,7 +401,7 @@ func TestHandshake(t *testing.T) { ...@@ -382,7 +401,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - read error ", func(t *testing.T) { t.Run("Handle - read error ", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -401,7 +420,7 @@ func TestHandshake(t *testing.T) { ...@@ -401,7 +420,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - write error ", func(t *testing.T) { t.Run("Handle - write error ", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -428,7 +447,7 @@ func TestHandshake(t *testing.T) { ...@@ -428,7 +447,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - ack read error ", func(t *testing.T) { t.Run("Handle - ack read error ", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -457,7 +476,7 @@ func TestHandshake(t *testing.T) { ...@@ -457,7 +476,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - networkID mismatch ", func(t *testing.T) { t.Run("Handle - networkID mismatch ", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -496,7 +515,7 @@ func TestHandshake(t *testing.T) { ...@@ -496,7 +515,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - duplicate handshake", func(t *testing.T) { t.Run("Handle - duplicate handshake", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -558,7 +577,7 @@ func TestHandshake(t *testing.T) { ...@@ -558,7 +577,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - invalid ack", func(t *testing.T) { t.Run("Handle - invalid ack", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -593,7 +612,7 @@ func TestHandshake(t *testing.T) { ...@@ -593,7 +612,7 @@ func TestHandshake(t *testing.T) {
}) })
t.Run("Handle - advertisable error", func(t *testing.T) { t.Run("Handle - advertisable error", func(t *testing.T) {
handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, logger) handshakeService, err := handshake.New(signer1, aaddresser, node1Info.BzzAddress.Overlay, networkID, false, "", logger)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -67,9 +67,10 @@ func (m *Syn) GetObservedUnderlay() []byte { ...@@ -67,9 +67,10 @@ func (m *Syn) GetObservedUnderlay() []byte {
} }
type Ack struct { type Ack struct {
Address *BzzAddress `protobuf:"bytes,1,opt,name=Address,proto3" json:"Address,omitempty"` Address *BzzAddress `protobuf:"bytes,1,opt,name=Address,proto3" json:"Address,omitempty"`
NetworkID uint64 `protobuf:"varint,2,opt,name=NetworkID,proto3" json:"NetworkID,omitempty"` NetworkID uint64 `protobuf:"varint,2,opt,name=NetworkID,proto3" json:"NetworkID,omitempty"`
Light bool `protobuf:"varint,3,opt,name=Light,proto3" json:"Light,omitempty"` Light bool `protobuf:"varint,3,opt,name=Light,proto3" json:"Light,omitempty"`
WelcomeMessage string `protobuf:"bytes,99,opt,name=WelcomeMessage,proto3" json:"WelcomeMessage,omitempty"`
} }
func (m *Ack) Reset() { *m = Ack{} } func (m *Ack) Reset() { *m = Ack{} }
...@@ -126,6 +127,13 @@ func (m *Ack) GetLight() bool { ...@@ -126,6 +127,13 @@ func (m *Ack) GetLight() bool {
return false return false
} }
func (m *Ack) GetWelcomeMessage() string {
if m != nil {
return m.WelcomeMessage
}
return ""
}
type SynAck struct { type SynAck struct {
Syn *Syn `protobuf:"bytes,1,opt,name=Syn,proto3" json:"Syn,omitempty"` Syn *Syn `protobuf:"bytes,1,opt,name=Syn,proto3" json:"Syn,omitempty"`
Ack *Ack `protobuf:"bytes,2,opt,name=Ack,proto3" json:"Ack,omitempty"` Ack *Ack `protobuf:"bytes,2,opt,name=Ack,proto3" json:"Ack,omitempty"`
...@@ -248,25 +256,26 @@ func init() { ...@@ -248,25 +256,26 @@ func init() {
func init() { proto.RegisterFile("handshake.proto", fileDescriptor_a77305914d5d202f) } func init() { proto.RegisterFile("handshake.proto", fileDescriptor_a77305914d5d202f) }
var fileDescriptor_a77305914d5d202f = []byte{ var fileDescriptor_a77305914d5d202f = []byte{
// 273 bytes of a gzipped FileDescriptorProto // 302 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcf, 0x48, 0xcc, 0x4b, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x91, 0x4d, 0x4b, 0xc3, 0x30,
0x29, 0xce, 0x48, 0xcc, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x84, 0x0b, 0x28, 0x1c, 0xc6, 0x97, 0x55, 0xf7, 0xf2, 0x77, 0x4c, 0x09, 0x0a, 0x45, 0x46, 0x08, 0x3d, 0x48, 0xf1,
0x19, 0x72, 0x31, 0x07, 0x57, 0xe6, 0x09, 0x69, 0x71, 0x09, 0xf8, 0x27, 0x15, 0xa7, 0x16, 0x95, 0x30, 0x51, 0x3f, 0xc1, 0x86, 0x17, 0x61, 0x3a, 0x48, 0x11, 0xc1, 0x93, 0x7d, 0x09, 0xed, 0xe8,
0xa5, 0xa6, 0x84, 0xe6, 0xa5, 0xa4, 0x16, 0xe5, 0x24, 0x56, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x4c, 0x47, 0x52, 0x27, 0xdd, 0xa7, 0x10, 0x3f, 0x95, 0xc7, 0x1d, 0x3d, 0x4a, 0xfb, 0x45, 0xa4,
0x04, 0x61, 0x88, 0x2b, 0x65, 0x71, 0x31, 0x3b, 0x26, 0x67, 0x0b, 0xe9, 0x73, 0xb1, 0x3b, 0xa6, 0xd9, 0x4b, 0x75, 0x1e, 0x9f, 0x97, 0x36, 0xbf, 0x27, 0x81, 0xc3, 0xc8, 0x15, 0x81, 0x8a, 0xdc,
0xa4, 0x14, 0xa5, 0x16, 0x17, 0x83, 0x55, 0x72, 0x1b, 0x89, 0xea, 0x21, 0xec, 0x71, 0xaa, 0xaa, 0x98, 0xf7, 0x67, 0x32, 0x49, 0x13, 0xdc, 0xde, 0x1a, 0xd6, 0x25, 0x18, 0x4e, 0x26, 0xf0, 0x39,
0x82, 0x4a, 0x06, 0xc1, 0x54, 0x09, 0xc9, 0x70, 0x71, 0xfa, 0xa5, 0x96, 0x94, 0xe7, 0x17, 0x65, 0x1c, 0x8d, 0x3d, 0xc5, 0xe5, 0x9c, 0x07, 0x0f, 0x22, 0xe0, 0x72, 0xea, 0x66, 0x26, 0xa2, 0xc8,
0x7b, 0xba, 0x48, 0x30, 0x29, 0x30, 0x6a, 0xb0, 0x04, 0x21, 0x04, 0x84, 0x44, 0xb8, 0x58, 0x7d, 0xee, 0xb0, 0x7f, 0xbe, 0xf5, 0x81, 0xc0, 0x18, 0xf8, 0x31, 0xbe, 0x80, 0xe6, 0x20, 0x08, 0x24,
0x32, 0xd3, 0x33, 0x4a, 0x24, 0x98, 0x15, 0x18, 0x35, 0x38, 0x82, 0x20, 0x1c, 0x25, 0x1f, 0x2e, 0x57, 0x4a, 0x57, 0x0f, 0xae, 0x4e, 0xfa, 0xd5, 0x41, 0xc3, 0xc5, 0x62, 0x1d, 0xb2, 0x4d, 0x0b,
0xb6, 0xe0, 0xca, 0x3c, 0x90, 0x75, 0x0a, 0x60, 0x87, 0x42, 0xad, 0xe2, 0x43, 0xb2, 0x2a, 0xb8, 0xf7, 0xa0, 0x7d, 0xcf, 0xd3, 0xb7, 0x44, 0xc6, 0xb7, 0x37, 0x66, 0x9d, 0x22, 0x7b, 0x8f, 0x55,
0x32, 0x2f, 0x08, 0xec, 0x07, 0x05, 0xb0, 0xbb, 0xc0, 0x26, 0xa3, 0xaa, 0x70, 0x4c, 0xce, 0x0e, 0x06, 0x3e, 0x86, 0xfd, 0xd1, 0x24, 0x8c, 0x52, 0xd3, 0xa0, 0xc8, 0x6e, 0xb1, 0x95, 0xc0, 0x67,
0x02, 0x49, 0x29, 0x25, 0x70, 0x71, 0x21, 0x1c, 0x26, 0x24, 0xc5, 0xc5, 0x81, 0xe6, 0x57, 0x38, 0xd0, 0x7d, 0xe4, 0x53, 0x3f, 0x79, 0xe1, 0x77, 0x5c, 0x29, 0x37, 0xe4, 0xa6, 0x4f, 0x91, 0xdd,
0x1f, 0xe4, 0xd6, 0xe0, 0xcc, 0xf4, 0xbc, 0xc4, 0x92, 0xd2, 0xa2, 0x54, 0xb0, 0x89, 0x3c, 0x41, 0x66, 0x3b, 0xae, 0x35, 0x82, 0x86, 0x93, 0x89, 0x12, 0x8b, 0xea, 0x45, 0x6b, 0xa4, 0xee, 0x2f,
0x08, 0x01, 0x21, 0x09, 0x2e, 0x76, 0xff, 0x32, 0x88, 0x46, 0x66, 0xb0, 0x1c, 0x8c, 0xeb, 0x24, 0x24, 0x27, 0x13, 0x4c, 0x8f, 0xa5, 0x9a, 0x5f, 0x13, 0xfc, 0x6d, 0x0c, 0xfc, 0x98, 0x95, 0x91,
0x73, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xf5, 0x0c, 0x50, 0x0d, 0xc0, 0xa7, 0xd0, 0xda, 0xb9, 0x94, 0xad, 0x2e, 0x37, 0x39, 0x93, 0x50,
0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x4c, 0x05, 0x49, 0x49, 0x6c, 0xb8, 0xe9, 0xab, 0xe4, 0xfa, 0x8f, 0x1d, 0x56, 0x19, 0xd8, 0x84, 0xe6, 0x78, 0xbe, 0xfa, 0xd0,
0xe0, 0xe0, 0x37, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x63, 0xc1, 0x05, 0xdf, 0x91, 0x01, 0x00, 0xd0, 0xd9, 0x46, 0x0e, 0x7b, 0x9f, 0x39, 0x41, 0xcb, 0x9c, 0xa0, 0xef, 0x9c, 0xa0, 0xf7, 0x82,
0x00, 0xd4, 0x96, 0x05, 0xa9, 0x7d, 0x15, 0xa4, 0xf6, 0x54, 0x9f, 0x79, 0x5e, 0x43, 0xbf, 0xd3, 0xf5,
0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9d, 0x61, 0xea, 0x46, 0xba, 0x01, 0x00, 0x00,
} }
func (m *Syn) Marshal() (dAtA []byte, err error) { func (m *Syn) Marshal() (dAtA []byte, err error) {
...@@ -319,6 +328,15 @@ func (m *Ack) MarshalToSizedBuffer(dAtA []byte) (int, error) { ...@@ -319,6 +328,15 @@ func (m *Ack) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i _ = i
var l int var l int
_ = l _ = l
if len(m.WelcomeMessage) > 0 {
i -= len(m.WelcomeMessage)
copy(dAtA[i:], m.WelcomeMessage)
i = encodeVarintHandshake(dAtA, i, uint64(len(m.WelcomeMessage)))
i--
dAtA[i] = 0x6
i--
dAtA[i] = 0x9a
}
if m.Light { if m.Light {
i-- i--
if m.Light { if m.Light {
...@@ -480,6 +498,10 @@ func (m *Ack) Size() (n int) { ...@@ -480,6 +498,10 @@ func (m *Ack) Size() (n int) {
if m.Light { if m.Light {
n += 2 n += 2
} }
l = len(m.WelcomeMessage)
if l > 0 {
n += 2 + l + sovHandshake(uint64(l))
}
return n return n
} }
...@@ -718,6 +740,38 @@ func (m *Ack) Unmarshal(dAtA []byte) error { ...@@ -718,6 +740,38 @@ func (m *Ack) Unmarshal(dAtA []byte) error {
} }
} }
m.Light = bool(v != 0) m.Light = bool(v != 0)
case 99:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field WelcomeMessage", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowHandshake
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthHandshake
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthHandshake
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.WelcomeMessage = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipHandshake(dAtA[iNdEx:]) skippy, err := skipHandshake(dAtA[iNdEx:])
......
...@@ -16,6 +16,7 @@ message Ack { ...@@ -16,6 +16,7 @@ message Ack {
BzzAddress Address = 1; BzzAddress Address = 1;
uint64 NetworkID = 2; uint64 NetworkID = 2;
bool Light = 3; bool Light = 3;
string WelcomeMessage = 99;
} }
message SynAck { message SynAck {
...@@ -27,4 +28,4 @@ message BzzAddress { ...@@ -27,4 +28,4 @@ message BzzAddress {
bytes Underlay = 1; bytes Underlay = 1;
bytes Signature = 2; bytes Signature = 2;
bytes Overlay = 3; bytes Overlay = 3;
} }
\ No newline at end of file
...@@ -60,14 +60,15 @@ type Service struct { ...@@ -60,14 +60,15 @@ type Service struct {
} }
type Options struct { type Options struct {
PrivateKey *ecdsa.PrivateKey PrivateKey *ecdsa.PrivateKey
NATAddr string NATAddr string
DisableWS bool DisableWS bool
DisableQUIC bool DisableQUIC bool
LightNode bool LightNode bool
Addressbook addressbook.Putter WelcomeMessage string
Logger logging.Logger Addressbook addressbook.Putter
Tracer *tracing.Tracer Logger logging.Logger
Tracer *tracing.Tracer
} }
func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay swarm.Address, addr string, func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay swarm.Address, addr string,
...@@ -181,7 +182,7 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay ...@@ -181,7 +182,7 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
} }
} }
handshakeService, err := handshake.New(signer, advertisableAddresser, overlay, networkID, o.LightNode, o.Logger) handshakeService, err := handshake.New(signer, advertisableAddresser, overlay, networkID, o.LightNode, o.WelcomeMessage, o.Logger)
if err != nil { if err != nil {
return nil, fmt.Errorf("handshake service: %w", err) return nil, fmt.Errorf("handshake service: %w", err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment