Commit b84f1a6e authored by suyanlong's avatar suyanlong

Fixed local bug

parent 3e01e21c
Pipeline #7994 canceled with stages
......@@ -3,11 +3,10 @@ package peermgr
import (
"errors"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/sirupsen/logrus"
"github.com/link33/sidecar/internal/port"
"github.com/link33/sidecar/internal/router"
"github.com/link33/sidecar/model/pb"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/sirupsen/logrus"
)
var (
......@@ -17,13 +16,19 @@ var (
type local struct {
id peer.ID
privKey crypto.PrivateKey
tag string
rev chan *pb.Message
rout router.Router
logger logrus.FieldLogger
}
func newLocal(id peer.ID) *local {
return &local{
id: id,
tag: Office,
rev: make(chan *pb.Message, 10),
}
}
func (l *local) ID() string {
return l.id.String()
}
......
......@@ -2,6 +2,7 @@ package peermgr
import (
"github.com/libp2p/go-libp2p-core/peer"
"github.com/link33/sidecar/internal"
"github.com/link33/sidecar/internal/port"
"github.com/link33/sidecar/model/pb"
)
......@@ -11,13 +12,11 @@ type ConnectHandler func(string)
//go:generate mockgen -destination mock_peermgr/mock_peermgr.go -package mock_peermgr -source peermgr.go
type PeerManager interface {
DHTManager
internal.Launcher
// Start
Start() error
DHTManager
// Stop
Stop() error
Handler
Connect(info *peer.AddrInfo) (string, error)
......@@ -31,8 +30,6 @@ type PeerManager interface {
SendWithPort(s port.Port, msg *pb.Message) (*pb.Message, error)
GetRemotePeerInfo(id string) (*pb.PeerInfo, error)
Handler
}
type Handler interface {
......
......@@ -103,13 +103,7 @@ func (swarm *Swarm) Start() error {
if err != nil {
return err
}
l := &local{
id: swarm.id,
privKey: swarm.privKey,
tag: Office,
rev: make(chan *pb.Message),
rout: swarm.router,
}
l := newLocal(swarm.id)
swarm.add(l)
swarm.p2p.SetMessageHandler(swarm.handleMessage)
if err := swarm.RegisterMsgHandler(pb.Message_ADDRESS_GET, swarm.handleGetAddressMessage); err != nil {
......
package router
import (
"github.com/link33/sidecar/internal"
"github.com/link33/sidecar/internal/port"
"github.com/link33/sidecar/model/pb"
)
//go:generate mockgen -destination mock_router/mock_router.go -package mock_router -source interface.go
type Router interface {
// Start starts the router module
Start() error
// Stop
Stop() error
internal.Launcher
Add(p port.Port) error
......
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