Commit 34086771 authored by suyanlong's avatar suyanlong

optimized appchain struct

parent 5aaf11a4
...@@ -28,6 +28,7 @@ type appChain struct { ...@@ -28,6 +28,7 @@ type appChain struct {
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
cryptor txcrypto.Cryptor cryptor txcrypto.Cryptor
msgCh chan *pb.Message
} }
func NewPort(client plugins.Client, cryptor txcrypto.Cryptor, logger logrus.FieldLogger) (port.Port, error) { func NewPort(client plugins.Client, cryptor txcrypto.Cryptor, logger logrus.FieldLogger) (port.Port, error) {
...@@ -39,6 +40,7 @@ func NewPort(client plugins.Client, cryptor txcrypto.Cryptor, logger logrus.Fiel ...@@ -39,6 +40,7 @@ func NewPort(client plugins.Client, cryptor txcrypto.Cryptor, logger logrus.Fiel
recvCh: make(chan *pb.IBTP, 1024), recvCh: make(chan *pb.IBTP, 1024),
ctx: ctx, ctx: ctx,
cancel: cancel, cancel: cancel,
msgCh: make(chan *pb.Message, 10),
}, nil }, nil
} }
......
...@@ -79,7 +79,6 @@ func (a *appChain) AsyncSend(msg *pb.Message) error { ...@@ -79,7 +79,6 @@ func (a *appChain) AsyncSend(msg *pb.Message) error {
// ListenIBTPX 监听IBTPX数据。 // ListenIBTPX 监听IBTPX数据。
func (a *appChain) ListenIBTPX() <-chan *pb.Message { func (a *appChain) ListenIBTPX() <-chan *pb.Message {
ibtpCh := a.ListenIBTP() ibtpCh := a.ListenIBTP()
msgCh := make(chan *pb.Message, 10)
func() { func() {
for { for {
select { select {
...@@ -87,13 +86,13 @@ func (a *appChain) ListenIBTPX() <-chan *pb.Message { ...@@ -87,13 +86,13 @@ func (a *appChain) ListenIBTPX() <-chan *pb.Message {
//TODO ibtp to ibtpx //TODO ibtp to ibtpx
data, _ := ibtp.Marshal() data, _ := ibtp.Marshal()
msg := pb.Msg(pb.Message_IBTP_SEND, true, data) msg := pb.Msg(pb.Message_IBTP_SEND, true, data)
msgCh <- msg a.msgCh <- msg
case <-a.ctx.Done(): case <-a.ctx.Done():
break break
} }
} }
}() }()
return msgCh return a.msgCh
} }
// 同一个接口,不同的实现,行为可以不一样。 // 同一个接口,不同的实现,行为可以不一样。
......
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