Commit 115d161d authored by suyanlong's avatar suyanlong

refactor code

parent 522ebba0
...@@ -61,38 +61,38 @@ func (s *sidecar) Receive(msg *pb.Message) { ...@@ -61,38 +61,38 @@ func (s *sidecar) Receive(msg *pb.Message) {
s.rev <- msg s.rev <- msg
} }
type stream struct { type tcpTmpStream struct {
s network.Stream s network.Stream
tag string tag string
rev chan *pb.Message rev chan *pb.Message
} }
func newStream(s network.Stream, tag string) *stream { func newStream(s network.Stream, tag string) *tcpTmpStream {
rec := make(chan *pb.Message, port.Capacity) rec := make(chan *pb.Message, port.Capacity)
return &stream{ return &tcpTmpStream{
s: s, s: s,
tag: tag, tag: tag,
rev: rec, rev: rec,
} }
} }
func (s *stream) ID() string { func (s *tcpTmpStream) ID() string {
return s.s.RemotePeerID() return s.s.RemotePeerID()
} }
func (s *stream) Type() string { func (s *tcpTmpStream) Type() string {
return port.Sidecar return port.Sidecar
} }
func (s *stream) Name() string { func (s *tcpTmpStream) Name() string {
return s.ID() return s.ID()
} }
func (s *stream) Tag() string { func (s *tcpTmpStream) Tag() string {
return s.tag return s.tag
} }
func (s *stream) Send(msg *pb.Message) (*pb.Message, error) { func (s *tcpTmpStream) Send(msg *pb.Message) (*pb.Message, error) {
return Send(s.s.Send, msg) return Send(s.s.Send, msg)
} }
...@@ -114,7 +114,7 @@ func Send(sender func([]byte) ([]byte, error), msg *pb.Message) (*pb.Message, er ...@@ -114,7 +114,7 @@ func Send(sender func([]byte) ([]byte, error), msg *pb.Message) (*pb.Message, er
return m, nil return m, nil
} }
func (s *stream) AsyncSend(msg *pb.Message) error { func (s *tcpTmpStream) AsyncSend(msg *pb.Message) error {
data, err := msg.Marshal() data, err := msg.Marshal()
if err != nil { if err != nil {
return fmt.Errorf("marshal message: %w", err) return fmt.Errorf("marshal message: %w", err)
...@@ -122,6 +122,6 @@ func (s *stream) AsyncSend(msg *pb.Message) error { ...@@ -122,6 +122,6 @@ func (s *stream) AsyncSend(msg *pb.Message) error {
return s.s.AsyncSend(data) return s.s.AsyncSend(data)
} }
func (s *stream) ListenIBTPX() <-chan *pb.Message { func (s *tcpTmpStream) ListenIBTPX() <-chan *pb.Message {
panic("implement me") panic("implement me")
} }
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