Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
1. Cleared all unnecessary Infof/Printf statements written in previous
commits
2. Manager.ReconnectTransports - there was bug after changing Edges
logic
3. Formatted, linted

Needed:

Tests with setup-node with changes in pkg/transport from this commit
  • Loading branch information
ayuryshev committed Apr 8, 2019
1 parent 8200dbc commit c3b0445
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pkg/app/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/skycoin/skywire/pkg/cipher"
)

func Example() {
func ExamplePacket() {
pk := cipher.PubKey{}
addr := Addr{pk, 0}
loopAddr := LoopAddr{0, addr}
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
// User represents a user of the manager.
type User struct {
Name string
PwSalt []byte/* */
PwSalt []byte /* */
PwHash cipher.SHA256
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestNodeSpawnAppValidations(t *testing.T) {
err string
}{
{&AppConfig{App: "chat", Version: "1.0", Port: 2}, "can't bind to reserved port 2"},
{&AppConfig{App: "chat", Version: "1.0", Port: 10}, "App chat is already started"},
{&AppConfig{App: "chat", Version: "1.0", Port: 10}, "app chat is already started"},
{&AppConfig{App: "foo", Version: "1.0", Port: 11}, "failed to run app executable: foo"},
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/setup/setup_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func ExampleProtocol_CreateLoop() {

fmt.Printf("packet: %v, payload: %v\n", packet, string(payload))

inProto.Respond(nil)
if err := inProto.Respond(nil); err != nil {
fmt.Println(err.Error())
}
}(inProto)

// TODO: create non-empty loop
Expand Down
26 changes: 7 additions & 19 deletions pkg/transport/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,21 @@ func settlementResponderHandshake(tm *Manager, tr Transport) (*Entry, error) {
return nil, fmt.Errorf("read: %s", err)
}

remote, errRemote := tm.Remote(tr.Edges())
if errRemote != nil {
return nil, errRemote
remote, err := tm.Remote(tr.Edges())
if err != nil {
return nil, err
}

if err := validateSignedEntry(sEntry, tr, remote); err != nil {
return nil, err
}

chkRemote := validateSignedEntry(sEntry, tr, remote)
chkLocal := validateSignedEntry(sEntry, tr, tm.Local())

tm.Logger.Infof(`validateSignedEntry
chkLocal: %v
chkRemote: %v
sEntry: %v
tr: %v
remote: %v
Edges: %v
tm.config.PubKey: %v
`, chkLocal, chkRemote, sEntry, tr, remote, tr.Edges(), tm.config.PubKey)

// Write second signature
// sEntry.Signatures[1] = sEntry.Entry.Signature(tm.config.SecKey)
if err := sEntry.Sign(tm.Local(), tm.config.SecKey); err != nil {
return nil, err
}

newEntry := tm.walkEntries(func(e *Entry) bool { return *e == *sEntry.Entry }) == nil

var err error
if sEntry.Entry.Public {
if !newEntry {
_, err = tm.config.DiscoveryClient.UpdateStatuses(context.Background(), &Status{ID: sEntry.Entry.ID, IsUp: true})
Expand Down
2 changes: 1 addition & 1 deletion pkg/transport/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestSettlementHandshakeExistingTransport(t *testing.T) {

}

func Example_verifySig() {
func Example_validateSignedEntry() {
mockEnv := newHsMockEnv()

tm, tr := mockEnv.m1, mockEnv.tr1
Expand Down
21 changes: 6 additions & 15 deletions pkg/transport/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package transport
import (
"context"
"errors"
"fmt"
"math/big"
"strings"
"sync"
Expand Down Expand Up @@ -122,15 +121,17 @@ func (tm *Manager) ReconnectTransports(ctx context.Context) {
entries := tm.entries
tm.mu.RUnlock()
for _, entry := range entries {
if entry.Edges()[0] != tm.config.PubKey {
continue
}

if tm.Transport(entry.ID) != nil {
continue
}

_, err := tm.createTransport(ctx, entry.Edges()[1], entry.Type, entry.Public)
remote, err := tm.Remote(entry.Edges())
if err != nil {
tm.Logger.Warnf("Failed to re-establish transport: %s", err)
continue
}
_, err = tm.createTransport(ctx, remote, entry.Type, entry.Public)
if err != nil {
tm.Logger.Warnf("Failed to re-establish transport: %s", err)
continue
Expand Down Expand Up @@ -349,12 +350,6 @@ func (tm *Manager) createTransport(ctx context.Context, remote cipher.PubKey, tp

func (tm *Manager) dialTransport(ctx context.Context, factory Factory, remote cipher.PubKey, public bool) (Transport, *Entry, error) {

fmt.Printf("Manager.dialTransport: %v %v\n", tm.Local(), remote)

if tm.Local() == remote {
fmt.Println("local and remote are equal. No need to dial")
}

tr, err := factory.Dial(ctx, remote)
if err != nil {
return nil, nil, err
Expand All @@ -375,10 +370,6 @@ func (tm *Manager) acceptTransport(ctx context.Context, factory Factory) (*Manag
return nil, err
}

tm.Logger.Infof("Trying to handshake with: %T %v\n", tr, tr)
tm.Logger.Infof("Handshake from factory: %T %v\n", factory, factory)
tm.Logger.Infof("Handshake: tr.Edges(): %v\n tr.Type(): %v\n", tr.Edges(), tr.Type())

var handshake settlementHandshake = settlementResponderHandshake
entry, err := handshake.Do(tm, tr, 30*time.Second)
if err != nil {
Expand Down
20 changes: 13 additions & 7 deletions pkg/transport/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestTransportManagerReEstablishTransports(t *testing.T) {

assert.Equal(t, []string{"mock"}, m1.Factories())

errCh := make(chan error)
errCh := make(chan error, 2)
go func() {
errCh <- m1.Serve(context.TODO())
}()
Expand All @@ -140,22 +140,28 @@ func TestTransportManagerReEstablishTransports(t *testing.T) {

require.NoError(t, m2.Close())

dEntry, err = client.GetTransportByID(context.TODO(), tr2.ID)
dEntry2, err := client.GetTransportByID(context.TODO(), tr2.ID)
require.NoError(t, err)
assert.False(t, dEntry.IsUp)
assert.False(t, dEntry2.IsUp)

m2, err = NewManager(c2, f2)
require.NoError(t, err)
go m2.Serve(context.TODO()) // nolint

time.Sleep(time.Second)
// errCh2 := make(chan error)
go func() {
errCh <- m2.Serve(context.TODO()) // nolint
}()

dEntry, err = client.GetTransportByID(context.TODO(), tr2.ID)
time.Sleep(time.Second) // TODO: this time.Sleep looks fishy - figure out later
dEntry3, err := client.GetTransportByID(context.TODO(), tr2.ID)
require.NoError(t, err)
assert.True(t, dEntry.IsUp)

assert.True(t, dEntry3.IsUp)

require.NoError(t, m2.Close())
require.NoError(t, m1.Close())

require.NoError(t, <-errCh)
require.NoError(t, <-errCh)
}

Expand Down

0 comments on commit c3b0445

Please sign in to comment.