Commit 115d161d authored by suyanlong's avatar suyanlong

refactor code

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