diff --git a/cmd/messaging-server/commands/root.go b/cmd/messaging-server/commands/root.go index 72ccccacab..ec1b789e92 100644 --- a/cmd/messaging-server/commands/root.go +++ b/cmd/messaging-server/commands/root.go @@ -3,7 +3,7 @@ package commands import ( "bufio" "encoding/json" - "github.com/skycoin/skywire/pkg/skymsg" + "github.com/skycoin/skywire/pkg/dms" "io" "log" "log/syslog" @@ -71,7 +71,7 @@ var rootCmd = &cobra.Command{ }() // Start - srv := skymsg.NewServer(conf.PubKey, conf.SecKey, conf.PublicAddress, client.NewHTTP(conf.Discovery)) + srv := dms.NewServer(conf.PubKey, conf.SecKey, conf.PublicAddress, client.NewHTTP(conf.Discovery)) log.Fatal(srv.ListenAndServe(conf.LocalAddress)) }, } diff --git a/cmd/skywire-cli/commands/node/transports.go b/cmd/skywire-cli/commands/node/transports.go index 52e2e8daa2..5a9244b96f 100644 --- a/cmd/skywire-cli/commands/node/transports.go +++ b/cmd/skywire-cli/commands/node/transports.go @@ -77,7 +77,7 @@ var ( ) func init() { - addTpCmd.Flags().StringVar(&transportType, "type", "skymsg", "type of transport to add") + addTpCmd.Flags().StringVar(&transportType, "type", "dms", "type of transport to add") addTpCmd.Flags().BoolVar(&public, "public", true, "whether to make the transport public") addTpCmd.Flags().DurationVarP(&timeout, "timeout", "t", 0, "if specified, sets an operation timeout") } diff --git a/pkg/skymsg/channel.go b/pkg/dms/channel.go similarity index 95% rename from pkg/skymsg/channel.go rename to pkg/dms/channel.go index d16936d5bf..b2f4b8d1b1 100644 --- a/pkg/skymsg/channel.go +++ b/pkg/dms/channel.go @@ -1,4 +1,4 @@ -package skymsg +package dms import ( "bytes" @@ -124,10 +124,6 @@ func (c *Channel) Read(p []byte) (n int, err error) { switch f.Type() { case FwdType: return c.bufRead(f.Pay(), p) - //if len(p) >= f.PayLen() { - // return copy(p, f.Pay()), nil - //} - //return 0, io.ErrShortBuffer case CloseType: c.close() return 0, io.ErrClosedPipe @@ -164,7 +160,6 @@ func (c *Channel) Write(p []byte) (int, error) { func (c *Channel) Close() error { if c.close() { _ = writeFrame(c.Conn, MakeFrame(CloseType, c.id, []byte{0})) - return nil } - return io.ErrClosedPipe + return nil } diff --git a/pkg/dms/channel_test.go b/pkg/dms/channel_test.go new file mode 100644 index 0000000000..ca04490e2c --- /dev/null +++ b/pkg/dms/channel_test.go @@ -0,0 +1 @@ +package dms diff --git a/pkg/skymsg/client.go b/pkg/dms/client.go similarity index 97% rename from pkg/skymsg/client.go rename to pkg/dms/client.go index 2dc2ade6c6..9f696cb395 100644 --- a/pkg/skymsg/client.go +++ b/pkg/dms/client.go @@ -1,4 +1,4 @@ -package skymsg +package dms import ( "context" @@ -33,11 +33,11 @@ var ( // Link from a client's perspective. type Link struct { log *logging.Logger - net.Conn // conn to skymsg server + net.Conn // conn to dms server local cipher.PubKey // local client's pk - remoteSrv cipher.PubKey // skymsg server's public key + remoteSrv cipher.PubKey // dms server's public key nextID uint16 // next unused channel ID - chans [math.MaxUint16]*Channel // channels to skymsg clients + chans [math.MaxUint16]*Channel // channels to dms clients mx sync.RWMutex wg sync.WaitGroup } diff --git a/pkg/skymsg/frame.go b/pkg/dms/frame.go similarity index 98% rename from pkg/skymsg/frame.go rename to pkg/dms/frame.go index b2948e1912..fc12617638 100644 --- a/pkg/skymsg/frame.go +++ b/pkg/dms/frame.go @@ -1,4 +1,4 @@ -package skymsg +package dms import ( "encoding/binary" @@ -9,7 +9,7 @@ import ( ) const ( - TpType = "skymsg" + TpType = "dms" hsTimeout = time.Second * 10 readBufLen = 10 diff --git a/pkg/dms/frame_test.go b/pkg/dms/frame_test.go new file mode 100644 index 0000000000..ca04490e2c --- /dev/null +++ b/pkg/dms/frame_test.go @@ -0,0 +1 @@ +package dms diff --git a/pkg/skymsg/server.go b/pkg/dms/server.go similarity index 99% rename from pkg/skymsg/server.go rename to pkg/dms/server.go index b9c93342c5..8439c52891 100644 --- a/pkg/skymsg/server.go +++ b/pkg/dms/server.go @@ -1,4 +1,4 @@ -package skymsg +package dms import ( "context" diff --git a/pkg/skymsg/server_test.go b/pkg/dms/server_test.go similarity index 99% rename from pkg/skymsg/server_test.go rename to pkg/dms/server_test.go index cf4a59d9a3..497b3c1516 100644 --- a/pkg/skymsg/server_test.go +++ b/pkg/dms/server_test.go @@ -1,4 +1,4 @@ -package skymsg +package dms import ( "context" diff --git a/pkg/node/node.go b/pkg/node/node.go index d349b36092..767b9bb187 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -5,7 +5,7 @@ import ( "context" "errors" "fmt" - "github.com/skycoin/skywire/pkg/skymsg" + "github.com/skycoin/skywire/pkg/dms" "io" "net" "net/rpc" @@ -79,7 +79,7 @@ type PacketRouter interface { type Node struct { config *Config router PacketRouter - messenger *skymsg.Client + messenger *dms.Client tm *transport.Manager rt routing.Table executer appExecuter @@ -116,7 +116,7 @@ func NewNode(config *Config) (*Node, error) { return nil, fmt.Errorf("invalid Messaging config: %s", err) } - node.messenger = skymsg.NewClient(mConfig.PubKey, mConfig.SecKey, mConfig.Discovery) + node.messenger = dms.NewClient(mConfig.PubKey, mConfig.SecKey, mConfig.Discovery) node.messenger.SetLogger(node.Logger.PackageLogger("dms")) trDiscovery, err := config.TransportDiscovery() @@ -199,7 +199,7 @@ func (node *Node) Start() error { ctx := context.Background() err := node.messenger.InitiateLinks(ctx, node.config.Messaging.ServerCount) if err != nil { - return fmt.Errorf("skymsg: %s", err) + return fmt.Errorf("dms: %s", err) } node.logger.Info("Connected to messaging servers") diff --git a/pkg/node/node_test.go b/pkg/node/node_test.go index 54a1060b34..ea6c97059c 100644 --- a/pkg/node/node_test.go +++ b/pkg/node/node_test.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "errors" - "github.com/skycoin/skywire/pkg/skymsg" + "github.com/skycoin/skywire/pkg/dms" "net" "os" "os/exec" @@ -75,7 +75,7 @@ func TestNodeStartClose(t *testing.T) { node := &Node{config: &Config{}, router: r, executer: executer, appsConf: conf, startedApps: map[string]*appBind{}, logger: logging.MustGetLogger("test")} mConf := &messaging.Config{PubKey: cipher.PubKey{}, SecKey: cipher.SecKey{}, Discovery: client.NewMock()} - node.messenger = skymsg.NewClient(mConf.PubKey, mConf.SecKey, mConf.Discovery) + node.messenger = dms.NewClient(mConf.PubKey, mConf.SecKey, mConf.Discovery) var err error tmConf := &transport.ManagerConfig{PubKey: cipher.PubKey{}, DiscoveryClient: transport.NewDiscoveryMock()} diff --git a/pkg/router/router.go b/pkg/router/router.go index 3a76a9e568..cc2d226c19 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -431,7 +431,7 @@ func (r *Router) setupProto(ctx context.Context) (*setup.Protocol, transport.Tra } // TODO(evanlinjin): need string constant for tp type. - tr, err := r.tm.CreateTransport(ctx, r.config.SetupNodes[0], "skymsg", false) + tr, err := r.tm.CreateTransport(ctx, r.config.SetupNodes[0], "dms", false) if err != nil { return nil, nil, fmt.Errorf("transport: %s", err) } diff --git a/pkg/setup/node.go b/pkg/setup/node.go index 0d08283dff..883f6a497b 100644 --- a/pkg/setup/node.go +++ b/pkg/setup/node.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "github.com/skycoin/skywire/pkg/skymsg" + "github.com/skycoin/skywire/pkg/dms" "log" "time" @@ -31,7 +31,7 @@ type Node struct { Logger *logging.Logger tm *transport.Manager - messenger *skymsg.Client + messenger *dms.Client srvCount int metrics metrics.Recorder } @@ -45,7 +45,7 @@ func NewNode(conf *Config, metrics metrics.Recorder) (*Node, error) { if lvl, err := logging.LevelFromString(conf.LogLevel); err == nil { logger.SetLevel(lvl) } - messenger := skymsg.NewClient(pk, sk, mClient.NewHTTP(conf.Messaging.Discovery)) + messenger := dms.NewClient(pk, sk, mClient.NewHTTP(conf.Messaging.Discovery)) messenger.SetLogger(logger.PackageLogger("messenger")) trDiscovery, err := trClient.NewHTTP(conf.TransportDiscovery, pk, sk) @@ -227,7 +227,7 @@ func (sn *Node) serveTransport(tr transport.Transport) error { } func (sn *Node) connectLoop(on cipher.PubKey, ld *LoopData) (noiseRes []byte, err error) { - tr, err := sn.tm.CreateTransport(context.Background(), on, skymsg.TpType, false) + tr, err := sn.tm.CreateTransport(context.Background(), on, dms.TpType, false) if err != nil { err = fmt.Errorf("transport: %s", err) return @@ -245,7 +245,7 @@ func (sn *Node) connectLoop(on cipher.PubKey, ld *LoopData) (noiseRes []byte, er } func (sn *Node) closeLoop(on cipher.PubKey, ld *LoopData) error { - tr, err := sn.tm.CreateTransport(context.Background(), on, skymsg.TpType, false) + tr, err := sn.tm.CreateTransport(context.Background(), on, dms.TpType, false) if err != nil { return fmt.Errorf("transport: %s", err) } @@ -261,7 +261,7 @@ func (sn *Node) closeLoop(on cipher.PubKey, ld *LoopData) error { } func (sn *Node) setupRule(pubKey cipher.PubKey, rule routing.Rule) (routeID routing.RouteID, err error) { - tr, err := sn.tm.CreateTransport(context.Background(), pubKey, skymsg.TpType, false) + tr, err := sn.tm.CreateTransport(context.Background(), pubKey, dms.TpType, false) if err != nil { err = fmt.Errorf("transport: %s", err) return diff --git a/pkg/skymsg/channel_test.go b/pkg/skymsg/channel_test.go deleted file mode 100644 index 806fc35c5a..0000000000 --- a/pkg/skymsg/channel_test.go +++ /dev/null @@ -1 +0,0 @@ -package skymsg diff --git a/pkg/skymsg/frame_test.go b/pkg/skymsg/frame_test.go deleted file mode 100644 index 806fc35c5a..0000000000 --- a/pkg/skymsg/frame_test.go +++ /dev/null @@ -1 +0,0 @@ -package skymsg