Commit 4a632a93 authored by suyanlong's avatar suyanlong

fix bug

parent 58cc8183
Pipeline #8624 failed with stages
...@@ -35,9 +35,9 @@ type App struct { ...@@ -35,9 +35,9 @@ type App struct {
config *repo.Config config *repo.Config
logger logrus.FieldLogger logger logrus.FieldLogger
manger internal.Launcher manger internal.Launcher
apiServer *api.Server apiServer *api.Server
managerPort *appchain.Manager appManagerPort *appchain.Manager
} }
// NewSidecar instantiates sidecar instance. // NewSidecar instantiates sidecar instance.
...@@ -71,14 +71,14 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error) ...@@ -71,14 +71,14 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
apiServer := api.NewServer(config, r, managerPort, loggers.Logger(loggers.ApiServer)) apiServer := api.NewServer(config, r, managerPort, loggers.Logger(loggers.ApiServer))
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
return &App{ return &App{
storage: store, storage: store,
logger: logger, logger: logger,
ctx: ctx, ctx: ctx,
cancel: cancel, cancel: cancel,
config: config, config: config,
manger: mg, manger: mg,
apiServer: apiServer, apiServer: apiServer,
managerPort: managerPort, appManagerPort: managerPort,
}, nil }, nil
} }
...@@ -88,7 +88,7 @@ func (s *App) Start() error { ...@@ -88,7 +88,7 @@ func (s *App) Start() error {
return err return err
} }
if err := s.managerPort.Start(); err != nil { if err := s.appManagerPort.Start(); err != nil {
return err return err
} }
...@@ -97,13 +97,5 @@ func (s *App) Start() error { ...@@ -97,13 +97,5 @@ func (s *App) Start() error {
// Stop stops three main components of sidecar app // Stop stops three main components of sidecar app
func (s *App) Stop() error { func (s *App) Stop() error {
if err := s.apiServer.Stop(); err != nil { return tool.SelectError(s.apiServer.Stop(), s.appManagerPort.Stop(), s.manger.Stop())
return err
}
if err := s.managerPort.Stop(); err != nil {
return err
}
return s.manger.Stop()
} }
...@@ -30,7 +30,7 @@ type appChain struct { ...@@ -30,7 +30,7 @@ type appChain struct {
logger logrus.FieldLogger logger logrus.FieldLogger
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
cryptor txcrypto.Cryptor cryptor txcrypto.Cryptor //TODO FIX BUG
msgCh chan *pb.Message msgCh chan *pb.Message
} }
...@@ -147,7 +147,7 @@ func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error { ...@@ -147,7 +147,7 @@ func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error {
contentByte := pd.Content contentByte := pd.Content
var err error var err error
if pd.Encrypted { if pd.Encrypted { //TODO
// TODO fix bug about mode value // TODO fix bug about mode value
contentByte, err = a.cryptor.Decrypt(contentByte, ibtp.To, repo.DirectMode) contentByte, err = a.cryptor.Decrypt(contentByte, ibtp.To, repo.DirectMode)
if err != nil { if err != nil {
......
...@@ -3,9 +3,6 @@ package peermgr ...@@ -3,9 +3,6 @@ package peermgr
import ( import (
"context" "context"
"fmt" "fmt"
"sync"
"time"
"github.com/Rican7/retry" "github.com/Rican7/retry"
"github.com/Rican7/retry/strategy" "github.com/Rican7/retry/strategy"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
...@@ -13,6 +10,8 @@ import ( ...@@ -13,6 +10,8 @@ import (
"github.com/meshplus/bitxhub-kit/crypto" "github.com/meshplus/bitxhub-kit/crypto"
network "github.com/meshplus/go-lightp2p" network "github.com/meshplus/go-lightp2p"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"sync"
"time"
"gitlab.33.cn/link33/sidecar/internal/port" "gitlab.33.cn/link33/sidecar/internal/port"
"gitlab.33.cn/link33/sidecar/internal/repo" "gitlab.33.cn/link33/sidecar/internal/repo"
...@@ -132,40 +131,42 @@ func (swarm *Swarm) Start() error { ...@@ -132,40 +131,42 @@ func (swarm *Swarm) Start() error {
for id, addr := range swarm.peers { for id, addr := range swarm.peers {
go func(remoteID string, addr *peer.AddrInfo) { go func(remoteID string, addr *peer.AddrInfo) {
if err := retry.Retry(func(attempt uint) error { err := retry.Retry(func(attempt uint) error {
if err := swarm.p2p.Connect(*addr); err != nil { err := swarm.p2p.Connect(*addr)
if attempt != 0 && attempt%5 == 0 { if err != nil {
swarm.logger.WithFields(logrus.Fields{ swarm.logger.WithFields(logrus.Fields{
"node": remoteID, "node": remoteID,
"error": err, "error": err,
}).Error("Connect failed") "attempt": attempt,
} }).Error("Connect failed", err)
return err return err
} }
return nil return nil
}, strategy.Wait(1*time.Second)); err != nil { }, strategy.Limit(5), strategy.Wait(time.Second))
swarm.logger.Error(err)
}
address, err := swarm.getRemoteAddress(addr.ID)
if err != nil { if err != nil {
swarm.logger.Error(err)
} else {
address, err := swarm.getRemoteAddress(addr.ID)
if err != nil {
swarm.logger.WithFields(logrus.Fields{
"node": remoteID,
"error": err,
}).Error("Get remote address failed")
}
swarm.addRemotePortByID(remoteID)
swarm.logger.WithFields(logrus.Fields{ swarm.logger.WithFields(logrus.Fields{
"node": remoteID, "node": remoteID,
"error": err, "address:": address,
}).Error("Get remote address failed") }).Info("Connect successfully")
} {
swarm.addRemotePortByID(remoteID) //swarm.lock.RLock()
swarm.logger.WithFields(logrus.Fields{ //defer swarm.lock.RUnlock()
"node": remoteID, //for _, handler := range swarm.connectHandlers {
"address:": address, // go func(connectHandler ConnectHandler, address string) {
}).Info("Connect successfully") // connectHandler(address)
{ // }(handler, address)
//swarm.lock.RLock() //}
//defer swarm.lock.RUnlock() }
//for _, handler := range swarm.connectHandlers {
// go func(connectHandler ConnectHandler, address string) {
// connectHandler(address)
// }(handler, address)
//}
} }
wg.Done() wg.Done()
}(id, addr) }(id, addr)
......
...@@ -106,7 +106,8 @@ func (r *router) Remove(p port.Port) error { ...@@ -106,7 +106,8 @@ func (r *router) Remove(p port.Port) error {
// 路由的有那些数据?需要区分!!! // 路由的有那些数据?需要区分!!!
func (r *router) Route(msg *pb.Message) error { func (r *router) Route(msg *pb.Message) error {
if msg == nil { if msg == nil {
r.logger.Error("msg = nil") r.logger.Error("msg == nil")
return errors.New("msg == nil")
} }
ibtpx := &pb.IBTPX{} ibtpx := &pb.IBTPX{}
err := ibtpx.Unmarshal(msg.Payload.Data) err := ibtpx.Unmarshal(msg.Payload.Data)
...@@ -194,8 +195,8 @@ func (r *router) Route(msg *pb.Message) error { ...@@ -194,8 +195,8 @@ func (r *router) Route(msg *pb.Message) error {
r.logger.Error(err) r.logger.Error(err)
return err return err
} }
case pb.Message_IBTP_GET: case pb.Message_IBTP_GET: //TODO
case pb.Message_IBTP_RECEIPT_GET: case pb.Message_IBTP_RECEIPT_GET: //TODO
default: default:
return nil return nil
} }
......
...@@ -7,11 +7,11 @@ import "basic.proto"; ...@@ -7,11 +7,11 @@ import "basic.proto";
// Inter-blockchain Transfer Protocol // Inter-blockchain Transfer Protocol
message IBTP { message IBTP {
enum Type { enum Type {
INTERCHAIN = 0; INTERCHAIN = 0; // 发送跨链交易。
RECEIPT_SUCCESS = 1; RECEIPT_SUCCESS = 1; // 接收成功
RECEIPT_FAILURE = 2; RECEIPT_FAILURE = 2; // 接收失败
ROLLBACK = 3; ROLLBACK = 3; // 回滚
RECEIPT_ROLLBACK = 4; RECEIPT_ROLLBACK = 4; // 接收回滚
} }
enum Category { enum Category {
......
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