Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
1. Renamed all `Ok` to `err`
2. Cleared commented Local(), Remote()
  • Loading branch information
ayuryshev committed Apr 4, 2019
1 parent 8e90eb3 commit 1ca7c11
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 52 deletions.
7 changes: 0 additions & 7 deletions pkg/messaging/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions pkg/node/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/transport/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions pkg/transport/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ 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
}

// 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
Expand Down
1 change: 1 addition & 0 deletions pkg/transport/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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())
}

Expand Down
10 changes: 4 additions & 6 deletions pkg/transport/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions pkg/transport/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1ca7c11

Please sign in to comment.