Commit b84f1a6e authored by suyanlong's avatar suyanlong

Fixed local bug

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