Skip to content

Commit

Permalink
Fix PR queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Sep 25, 2019
1 parent d7e140b commit 17ba146
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/app2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewClient(log *logging.Logger, localPK cipher.PubKey, pid ProcID, rpc RPCCl

// Dial dials the remote node using `remote`.
func (c *Client) Dial(remote network.Addr) (net.Conn, error) {
connID, assignedPort, err := c.rpc.Dial(remote)
connID, localPort, err := c.rpc.Dial(remote)
if err != nil {
return nil, err
}
Expand All @@ -49,7 +49,7 @@ func (c *Client) Dial(remote network.Addr) (net.Conn, error) {
local: network.Addr{
Net: remote.Net,
PubKey: c.pk,
Port: assignedPort,
Port: localPort,
},
remote: remote,
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/app2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func TestClient_Dial(t *testing.T) {

t.Run("ok", func(t *testing.T) {
dialConnID := uint16(1)
dialAssignedPort := routing.Port(1)
dialLocalPort := routing.Port(1)
var dialErr error

rpc := &MockRPCClient{}
rpc.On("Dial", remote).Return(dialConnID, dialAssignedPort, dialErr)
rpc.On("Dial", remote).Return(dialConnID, dialLocalPort, dialErr)

cl := NewClient(l, localPK, pid, rpc)

Expand All @@ -41,7 +41,7 @@ func TestClient_Dial(t *testing.T) {
local: network.Addr{
Net: remote.Net,
PubKey: localPK,
Port: dialAssignedPort,
Port: dialLocalPort,
},
remote: remote,
}
Expand All @@ -61,13 +61,13 @@ func TestClient_Dial(t *testing.T) {

t.Run("conn already exists", func(t *testing.T) {
dialConnID := uint16(1)
dialAssignedPort := routing.Port(1)
dialLocalPort := routing.Port(1)
var dialErr error

var closeErr error

rpc := &MockRPCClient{}
rpc.On("Dial", remote).Return(dialConnID, dialAssignedPort, dialErr)
rpc.On("Dial", remote).Return(dialConnID, dialLocalPort, dialErr)
rpc.On("CloseConn", dialConnID).Return(closeErr)

cl := NewClient(l, localPK, pid, rpc)
Expand All @@ -82,13 +82,13 @@ func TestClient_Dial(t *testing.T) {

t.Run("conn already exists, conn closed with error", func(t *testing.T) {
dialConnID := uint16(1)
dialAssignedPort := routing.Port(1)
dialLocalPort := routing.Port(1)
var dialErr error

closeErr := errors.New("close error")

rpc := &MockRPCClient{}
rpc.On("Dial", remote).Return(dialConnID, dialAssignedPort, dialErr)
rpc.On("Dial", remote).Return(dialConnID, dialLocalPort, dialErr)
rpc.On("CloseConn", dialConnID).Return(closeErr)

cl := NewClient(l, localPK, pid, rpc)
Expand Down
4 changes: 2 additions & 2 deletions pkg/app2/network/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func (a Addr) String() string {
return fmt.Sprintf("%s:%d", a.PubKey, a.Port)
}

// WrapAddr asserts type of the passed `net.Addr` and converts it
// ConvertAddr asserts type of the passed `net.Addr` and converts it
// to `Addr` if possible.
func WrapAddr(addr net.Addr) (Addr, error) {
func ConvertAddr(addr net.Addr) (Addr, error) {
switch a := addr.(type) {
case dmsg.Addr:
return Addr{
Expand Down
4 changes: 2 additions & 2 deletions pkg/app2/network/wrapped_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type WrappedConn struct {

// WrapConn wraps passed `conn`. Handles `net.Addr` type assertion.
func WrapConn(conn net.Conn) (net.Conn, error) {
l, err := WrapAddr(conn.LocalAddr())
l, err := ConvertAddr(conn.LocalAddr())
if err != nil {
return nil, err
}

r, err := WrapAddr(conn.RemoteAddr())
r, err := ConvertAddr(conn.RemoteAddr())
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/app2/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// RPCClient describes RPC interface to communicate with the server.
type RPCClient interface {
Dial(remote network.Addr) (connID uint16, assignedPort routing.Port, err error)
Dial(remote network.Addr) (connID uint16, localPort routing.Port, err error)
Listen(local network.Addr) (uint16, error)
Accept(lisID uint16) (connID uint16, remote network.Addr, err error)
Write(connID uint16, b []byte) (int, error)
Expand All @@ -33,7 +33,7 @@ func NewRPCClient(rpc *rpc.Client) RPCClient {
}

// Dial sends `Dial` command to the server.
func (c *rpcCLient) Dial(remote network.Addr) (connID uint16, assignedPort routing.Port, err error) {
func (c *rpcCLient) Dial(remote network.Addr) (connID uint16, localPort routing.Port, err error) {
var resp DialResp
if err := c.rpc.Call("Dial", &remote, &resp); err != nil {
return 0, 0, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/app2/rpc_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *RPCGateway) Dial(remote *network.Addr, resp *DialResp) error {
return err
}

localAddr, err := network.WrapAddr(conn.LocalAddr())
localAddr, err := network.ConvertAddr(conn.LocalAddr())
if err != nil {
free()
return err
Expand Down Expand Up @@ -127,10 +127,10 @@ func (r *RPCGateway) Accept(lisID *uint16, resp *AcceptResp) error {
return err
}

remote, ok := conn.RemoteAddr().(network.Addr)
if !ok {
remote, err := network.ConvertAddr(conn.RemoteAddr())
if err != nil {
free()
return errors.New("wrong type for remote addr")
return err
}

resp.Remote = remote
Expand Down

0 comments on commit 17ba146

Please sign in to comment.