Skip to content

Commit

Permalink
Impement net interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Sep 16, 2019
1 parent 7bcafc9 commit cf5e105
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
3 changes: 2 additions & 1 deletion pkg/app2/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app2

import (
"net"
"net/rpc"

"github.com/skycoin/dmsg/cipher"
Expand Down Expand Up @@ -52,7 +53,7 @@ func (c *Client) Dial(remote routing.Addr) (*Conn, error) {
}

// Listen listens on the specified `port` for the incoming connections.
func (c *Client) Listen(port routing.Port) (*Listener, error) {
func (c *Client) Listen(port routing.Port) (net.Listener, error) {
local := routing.Addr{
PubKey: c.pk,
Port: port,
Expand Down
16 changes: 15 additions & 1 deletion pkg/app2/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package app2

import (
"net"
"time"

"github.com/pkg/errors"
"github.com/skycoin/skywire/pkg/routing"
)

// Conn is a connection from app client to the server.
type Conn struct {
id uint16
rpc ConnRPCClient
rpc ServerRPCClient
local routing.Addr
remote routing.Addr
}
Expand All @@ -33,3 +35,15 @@ func (c *Conn) LocalAddr() net.Addr {
func (c *Conn) RemoteAddr() net.Addr {
return c.remote
}

func (c *Conn) SetDeadline(t time.Time) error {
return errors.New("method not implemented")
}

func (c *Conn) SetReadDeadline(t time.Time) error {
return errors.New("method not implemented")
}

func (c *Conn) SetWriteDeadline(t time.Time) error {
return errors.New("method not implemented")
}
4 changes: 2 additions & 2 deletions pkg/app2/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
// Listener is a listener for app server connections.
type Listener struct {
id uint16
rpc ListenerRPCClient
rpc ServerRPCClient
addr routing.Addr
}

func (l *Listener) Accept() (*Conn, error) {
func (l *Listener) Accept() (net.Conn, error) {
connID, err := l.rpc.Accept(l.id)
if err != nil {
return nil, err
Expand Down
18 changes: 0 additions & 18 deletions pkg/app2/server_rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,6 @@ type ServerRPCClient interface {
CloseListener(id uint16) error
}

// ListenerRPCClient describes RPC interface to communicate with the server.
// Contains funcs for `Listener` and `Conn`.
type ListenerRPCClient interface {
Accept(id uint16) (uint16, error)
CloseListener(id uint16) error
Write(connID uint16, b []byte) (int, error)
Read(connID uint16, b []byte) (int, error)
CloseConn(id uint16) error
}

// ConnRPCClient describes RPC interface to communicate with the server.
// Contains funcs for `Conn`.
type ConnRPCClient interface {
Write(id uint16, b []byte) (int, error)
Read(id uint16, b []byte) (int, error)
CloseConn(id uint16) error
}

// serverRPCClient implements `ServerRPCClient`.
type serverRPCCLient struct {
rpc *rpc.Client
Expand Down

0 comments on commit cf5e105

Please sign in to comment.