Skip to content

Commit

Permalink
Ensure ClientConn' and ServerConn's PKs are being accessed throug…
Browse files Browse the repository at this point in the history
…h func
  • Loading branch information
Darkren committed Jun 15, 2019
1 parent c495a3a commit bb64f66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/dmsg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func NewClientConn(log *logging.Logger, conn net.Conn, local, remote cipher.PubK
return cc
}

func (c *ClientConn) PK() cipher.PubKey {
return c.remoteSrv
}

func (c *ClientConn) getNextInitID(ctx context.Context) (uint16, error) {
for {
select {
Expand Down
16 changes: 8 additions & 8 deletions pkg/dmsg/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,22 @@ func TestServer_Serve(t *testing.T) {
// must have ServerConn for A
aServerConn, ok := s.getConn(aPK)
require.Equal(t, true, ok)
require.Equal(t, aPK, aServerConn.remoteClient)
require.Equal(t, aPK, aServerConn.PK())

// must have ServerConn for B
bServerConn, ok := s.getConn(bPK)
require.Equal(t, true, ok)
require.Equal(t, bPK, bServerConn.remoteClient)
require.Equal(t, bPK, bServerConn.PK())

// must have a ClientConn
aClientConn, ok := a.getConn(sPK)
require.Equal(t, true, ok)
require.Equal(t, sPK, aClientConn.remoteSrv)
require.Equal(t, sPK, aClientConn.PK())

// must have a ClientConn
bClientConn, ok := b.getConn(sPK)
require.Equal(t, true, ok)
require.Equal(t, sPK, bClientConn.remoteSrv)
require.Equal(t, sPK, bClientConn.PK())

// check whether nextConn's contents are as must be
bNextConn := bServerConn.nextConns[bClientConn.nextInitID-2]
Expand Down Expand Up @@ -410,24 +410,24 @@ func TestServer_Serve(t *testing.T) {
// get and check initiator's ServerConn
initiatorServConn, ok := s.getConn(initiator.pk)
require.Equal(t, true, ok)
require.Equal(t, initiator.pk, initiatorServConn.remoteClient)
require.Equal(t, initiator.pk, initiatorServConn.PK())

// get and check initiator's ClientConn
initiatorClientConn, ok := initiator.getConn(sPK)
require.Equal(t, true, ok)
require.Equal(t, sPK, initiatorClientConn.remoteSrv)
require.Equal(t, sPK, initiatorClientConn.PK())

remote := remotes[pickedRemotes[i]]

// get and check remote's ServerConn
remoteServConn, ok := s.getConn(remote.pk)
require.Equal(t, true, ok)
require.Equal(t, remote.pk, remoteServConn.remoteClient)
require.Equal(t, remote.pk, remoteServConn.PK())

// get and check remote's ClientConn
remoteClientConn, ok := remote.getConn(sPK)
require.Equal(t, true, ok)
require.Equal(t, sPK, remoteClientConn.remoteSrv)
require.Equal(t, sPK, remoteClientConn.PK())

// get initiator's nextConn
initiatorNextConn := initiatorServConn.nextConns[initiatorClientConn.nextInitID-2]
Expand Down

0 comments on commit bb64f66

Please sign in to comment.