diff --git a/pkg/messaging/channel.go b/pkg/messaging/channel.go index e10048ba5..3d4c28353 100644 --- a/pkg/messaging/channel.go +++ b/pkg/messaging/channel.go @@ -128,13 +128,6 @@ func (c *channel) Close() error { return nil } -func (c *channel) Local() cipher.PubKey { - return c.link.Local() -} - -func (c *channel) Remote() cipher.PubKey { - return c.remotePK -} func (c *channel) SetDeadline(t time.Time) error { c.deadline = t diff --git a/pkg/node/rpc.go b/pkg/node/rpc.go index 4d65c4403..e6dc53f53 100644 --- a/pkg/node/rpc.go +++ b/pkg/node/rpc.go @@ -70,19 +70,21 @@ type TransportSummary struct { } func newTransportSummary(tm *transport.Manager, tp *transport.ManagedTransport, includeLogs bool) *TransportSummary { - if remote, Ok := tm.Remote(tp.Edges()); Ok == nil { - summary := TransportSummary{ - ID: tp.ID, - Local: tm.Local(), - Remote: remote, - Type: tp.Type(), - } - if includeLogs { - summary.Log = tp.LogEntry - } - return &summary + remote, err := tm.Remote(tp.Edges()) + if err != nil { + return &TransportSummary{} + } + + summary := &TransportSummary{ + ID: tp.ID, + Local: tm.Local(), + Remote: remote, + Type: tp.Type(), + } + if includeLogs { + summary.Log = tp.LogEntry } - return &TransportSummary{} + return summary } // Summary provides a summary of an AppNode. @@ -182,7 +184,7 @@ func (r *RPC) Transports(in *TransportsIn, out *[]*TransportSummary) error { return true } r.node.tm.WalkTransports(func(tp *transport.ManagedTransport) bool { - if remote, Ok := r.node.tm.Remote(tp.Edges()); Ok == nil { + if remote, err := r.node.tm.Remote(tp.Edges()); err == nil { if typeIncluded(tp.Type()) && pkIncluded(r.node.tm.Local(), remote) { *out = append(*out, newTransportSummary(r.node.tm, tp, in.ShowLogs)) } diff --git a/pkg/router/router.go b/pkg/router/router.go index 4042dc95b..9053d73a4 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -485,11 +485,9 @@ func (r *Router) advanceNoiseHandshake(addr *app.LoopAddr, noiseMsg []byte) (ni func (r *Router) isSetupTransport(tr transport.Transport) bool { for _, pk := range r.config.SetupNodes { - remote, Ok := r.tm.Remote(tr.Edges()) - if Ok == nil { - if remote == pk { - return true - } + remote, err := r.tm.Remote(tr.Edges()) + if err == nil && remote == pk { + return true } } diff --git a/pkg/transport/discovery_test.go b/pkg/transport/discovery_test.go index 82f4655fc..dc16337d0 100644 --- a/pkg/transport/discovery_test.go +++ b/pkg/transport/discovery_test.go @@ -15,25 +15,25 @@ func ExampleNewDiscoveryMock() { sEntry := &SignedEntry{Entry: entry} - if Ok := dc.RegisterTransports(context.TODO(), sEntry); Ok == nil { + if err := dc.RegisterTransports(context.TODO(), sEntry); err == nil { fmt.Println("RegisterTransport success") } else { fmt.Println(Ok.Error()) } - if entryWS, Ok := dc.GetTransportByID(context.TODO(), sEntry.Entry.ID); Ok == nil { + if entryWS, err := dc.GetTransportByID(context.TODO(), sEntry.Entry.ID); err == nil { fmt.Println("GetTransportByID success") fmt.Printf("entryWS.Entry.ID == sEntry.Entry.ID is %v\n", entryWS.Entry.ID == sEntry.Entry.ID) } else { fmt.Printf("%v", entryWS) } - if entriesWS, Ok := dc.GetTransportsByEdge(context.TODO(), entry.Edges()[0]); Ok == nil { + if entriesWS, err := dc.GetTransportsByEdge(context.TODO(), entry.Edges()[0]); err == nil { fmt.Println("GetTransportsByEdge success") fmt.Printf("entriesWS[0].Entry.Edges()[0] == entry.Edges()[0] is %v\n", entriesWS[0].Entry.Edges()[0] == entry.Edges()[0]) } - if _, Ok := dc.UpdateStatuses(context.TODO(), &Status{}); Ok == nil { + if _, err := dc.UpdateStatuses(context.TODO(), &Status{}); err == nil { fmt.Println("UpdateStatuses success") } else { fmt.Println(Ok.Error()) diff --git a/pkg/transport/entry.go b/pkg/transport/entry.go index de1ec97a3..24af3de75 100644 --- a/pkg/transport/entry.go +++ b/pkg/transport/entry.go @@ -109,8 +109,8 @@ func (se *SignedEntry) Index(pk cipher.PubKey) (byte, error) { // Sign sets Signature for a given PubKey in correct position func (se *SignedEntry) Sign(pk cipher.PubKey, secKey cipher.SecKey) error { - idx, Ok := se.Index(pk) - if Ok == nil { + idx, err := se.Index(pk) + if err == nil { se.Signatures[idx] = se.Entry.Signature(secKey) } return Ok @@ -118,8 +118,8 @@ func (se *SignedEntry) Sign(pk cipher.PubKey, secKey cipher.SecKey) error { // Signature gets Signature for a given PubKey from correct position func (se *SignedEntry) Signature(pk cipher.PubKey) (cipher.Sig, error) { - idx, Ok := se.Index(pk) - if Ok != nil { + idx, err := se.Index(pk) + if err != nil { return cipher.Sig{}, Ok } return se.Signatures[idx], nil diff --git a/pkg/transport/handshake.go b/pkg/transport/handshake.go index 5f3b0d05c..6d238484f 100644 --- a/pkg/transport/handshake.go +++ b/pkg/transport/handshake.go @@ -16,6 +16,7 @@ func (handshake settlementHandshake) Do(tm *Manager, tr Transport, timeout time. var entry *Entry errCh := make(chan error, 1) go func() { + fmt.Printf("IMMA HERE") e, err := handshake(tm, tr) entry = e errCh <- err diff --git a/pkg/transport/handshake_test.go b/pkg/transport/handshake_test.go index d1bee1f00..95c75f105 100644 --- a/pkg/transport/handshake_test.go +++ b/pkg/transport/handshake_test.go @@ -104,7 +104,7 @@ func Example_validateEntry() { entry := NewEntry(pk1, pk2, "mock", true) sEntry := NewSignedEntry(entry, pk1, sk1) - if Ok := validateSignedEntry(sEntry, tr, pk1); Ok != nil { + if err := validateSignedEntry(sEntry, tr, pk1); err != nil { fmt.Println(Ok.Error()) } diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index 8675ec36b..e3ae736b2 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -163,13 +163,11 @@ func (tm *Manager) CreateDefaultTransports(ctx context.Context) { for _, pk := range tm.config.DefaultNodes { exist := false tm.WalkTransports(func(tr *ManagedTransport) bool { - if remote, Ok := tm.Remote(tr.Edges()); Ok == nil { - if remote == pk { - exist = true - return false - } + remote, err := tm.Remote(tr.Edges()) + if err == nil && remote == pk { + exist = true + return false } - return true }) if exist { diff --git a/pkg/transport/mock.go b/pkg/transport/mock.go index a76dfbc83..af2d5f052 100644 --- a/pkg/transport/mock.go +++ b/pkg/transport/mock.go @@ -79,8 +79,6 @@ func (f *MockFactory) Type() string { type MockTransport struct { rw io.ReadWriteCloser edges [2]cipher.PubKey - // local cipher.PubKey - // remote cipher.PubKey context context.Context } @@ -120,16 +118,6 @@ func (m *MockTransport) Edges() [2]cipher.PubKey { return SortEdges(m.edges) } -// // Local returns the local static public key -// func (m *MockTransport) Local() cipher.PubKey { -// return m.local -// } - -// // Remote returns the remote public key fo the mock transport -// func (m *MockTransport) Remote() cipher.PubKey { -// return m.remote -// } - // SetDeadline sets a deadline for the write/read operations of the mock transport func (m *MockTransport) SetDeadline(t time.Time) error { // nolint