Commit fb308024 authored by Janos Guljas's avatar Janos Guljas

handle not configured functions in p2p/mock

parent a31ea6e3
...@@ -6,6 +6,7 @@ package mock ...@@ -6,6 +6,7 @@ package mock
import ( import (
"context" "context"
"errors"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
...@@ -44,14 +45,23 @@ func New(opts ...Option) *Service { ...@@ -44,14 +45,23 @@ func New(opts ...Option) *Service {
} }
func (s *Service) AddProtocol(spec p2p.ProtocolSpec) error { func (s *Service) AddProtocol(spec p2p.ProtocolSpec) error {
if s.addProtocolFunc == nil {
return errors.New("AddProtocol function not configured")
}
return s.addProtocolFunc(spec) return s.addProtocolFunc(spec)
} }
func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (overlay string, err error) { func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (overlay string, err error) {
if s.connectFunc == nil {
return "", errors.New("Connect function not configured")
}
return s.connectFunc(ctx, addr) return s.connectFunc(ctx, addr)
} }
func (s *Service) Disconnect(overlay string) error { func (s *Service) Disconnect(overlay string) error {
if s.disconnectFunc == nil {
return errors.New("Disconnect function not configured")
}
return s.disconnectFunc(overlay) return s.disconnectFunc(overlay)
} }
......
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