Skip to content
Snippets Groups Projects
Commit 24fc1395 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Add headers and perform a light refactor to remove some files with 'Tracker'...

Add headers and perform a light refactor to remove some files with 'Tracker' internal-only code, moving them to the bottom of the main file.
parent 13d8b4f0
No related branches found
No related tags found
2 merge requests!510Release,!262Add params options to bindings
Showing
with 312 additions and 207 deletions
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"fmt" "fmt"
"sync"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
...@@ -50,9 +58,14 @@ func NewKeystore(network, storageDir string, password []byte, regCode string) er ...@@ -50,9 +58,14 @@ func NewKeystore(network, storageDir string, password []byte, regCode string) er
// Login does not block on network connection, and instead loads and // Login does not block on network connection, and instead loads and
// starts subprocesses to perform network operations. // starts subprocesses to perform network operations.
// TODO: add in custom parameters instead of the default // TODO: add in custom parameters instead of the default
func Login(storageDir string, password []byte) (*Cmix, error) { func Login(storageDir string, password []byte, cmixParamsJSON []byte) (*Cmix,
paramsJSON := GetDefaultCMixParams() error) {
params, err := parseCMixParams(paramsJSON) if len(cmixParamsJSON) == 0 {
jww.WARN.Printf("cmix params not specified, using defaults...")
cmixParamsJSON = GetDefaultCMixParams()
}
params, err := parseCMixParams(cmixParamsJSON)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -68,3 +81,50 @@ func Login(storageDir string, password []byte) (*Cmix, error) { ...@@ -68,3 +81,50 @@ func Login(storageDir string, password []byte) (*Cmix, error) {
func (c *Cmix) GetID() int { func (c *Cmix) GetID() int {
return c.id return c.id
} }
// cmixTracker is a singleton used to keep track of extant Cmix objects,
// preventing race conditions created by passing it over the bindings
type cmixTracker struct {
clients map[int]*Cmix
count int
mux sync.RWMutex
}
// make a Cmix from an xxdk.Cmix, assigns it a unique ID,
// and adds it to the cmixTracker
func (ct *cmixTracker) make(c *xxdk.Cmix) *Cmix {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.clients[id] = &Cmix{
api: c,
id: id,
}
return ct.clients[id]
}
// get a Cmix from the cmixTracker given its ID
func (ct *cmixTracker) get(id int) (*Cmix, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
c, exist := ct.clients[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
// delete a Cmix if it exists in the cmixTracker
func (ct *cmixTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
delete(ct.clients, id)
}
package bindings
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/xxdk"
"sync"
)
// cmixTracker is a singleton used to keep track of extant Cmix objects,
// preventing race conditions created by passing it over the bindings
type cmixTracker struct {
clients map[int]*Cmix
count int
mux sync.RWMutex
}
// make a Cmix from an xxdk.Cmix, assigns it a unique ID,
// and adds it to the cmixTracker
func (ct *cmixTracker) make(c *xxdk.Cmix) *Cmix {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.clients[id] = &Cmix{
api: c,
id: id,
}
return ct.clients[id]
}
// get a Cmix from the cmixTracker given its ID
func (ct *cmixTracker) get(id int) (*Cmix, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
c, exist := ct.clients[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
// delete a Cmix if it exists in the cmixTracker
func (ct *cmixTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
delete(ct.clients, id)
}
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"sync"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/connect" "gitlab.com/elixxir/client/connect"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
) )
...@@ -19,6 +30,7 @@ var connectionTrackerSingleton = &connectionTracker{ ...@@ -19,6 +30,7 @@ var connectionTrackerSingleton = &connectionTracker{
type Connection struct { type Connection struct {
connection connect.Connection connection connect.Connection
id int id int
params xxdk.E2EParams
} }
// GetId returns the Connection.id // GetId returns the Connection.id
...@@ -32,9 +44,12 @@ func (c *Connection) GetId() int { ...@@ -32,9 +44,12 @@ func (c *Connection) GetId() int {
// partner.Manager is confirmed. // partner.Manager is confirmed.
// recipientContact - marshalled contact.Contact object // recipientContact - marshalled contact.Contact object
// myIdentity - marshalled ReceptionIdentity object // myIdentity - marshalled ReceptionIdentity object
func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( func (c *Cmix) Connect(e2eId int, recipientContact, e2eParamsJSON []byte) (
*Connection, error) { *Connection, error) {
paramsJSON := GetDefaultE2EParams() if len(e2eParamsJSON) == 0 {
jww.WARN.Printf("e2e params not specified, using defaults...")
e2eParamsJSON = GetDefaultE2EParams()
}
cont, err := contact.Unmarshal(recipientContact) cont, err := contact.Unmarshal(recipientContact)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -45,7 +60,7 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( ...@@ -45,7 +60,7 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) (
return nil, err return nil, err
} }
p, err := parseE2EParams(paramsJSON) p, err := parseE2EParams(e2eParamsJSON)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -55,21 +70,14 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( ...@@ -55,21 +70,14 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) (
return nil, err return nil, err
} }
return connectionTrackerSingleton.make(connection), nil return connectionTrackerSingleton.make(connection, p), nil
} }
// SendE2E is a wrapper for sending specifically to the Connection's partner.Manager // SendE2E is a wrapper for sending specifically to the Connection's partner.Manager
// Returns marshalled E2ESendReport // Returns marshalled E2ESendReport
func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) { func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) {
paramsJSON := GetDefaultE2EParams()
params, err := parseE2EParams(paramsJSON)
if err != nil {
return nil, err
}
rounds, mid, ts, err := c.connection.SendE2E(catalog.MessageType(mt), payload, rounds, mid, ts, err := c.connection.SendE2E(catalog.MessageType(mt), payload,
params.Base) c.params.Base)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -102,3 +110,52 @@ func (c *Connection) RegisterListener(messageType int, newListener Listener) err ...@@ -102,3 +110,52 @@ func (c *Connection) RegisterListener(messageType int, newListener Listener) err
_, err := c.connection.RegisterListener(catalog.MessageType(messageType), listener{l: newListener}) _, err := c.connection.RegisterListener(catalog.MessageType(messageType), listener{l: newListener})
return err return err
} }
// connectionTracker is a singleton used to keep track of extant clients, allowing
// for race condition free passing over the bindings
type connectionTracker struct {
connections map[int]*Connection
count int
mux sync.RWMutex
}
// make makes a client from an API client, assigning it a unique ID
func (ct *connectionTracker) make(c connect.Connection,
params xxdk.E2EParams) *Connection {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.connections[id] = &Connection{
connection: c,
id: id,
params: params,
}
return ct.connections[id]
}
//get returns a client given its ID
func (ct *connectionTracker) get(id int) (*Connection, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
c, exist := ct.connections[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
//deletes a client if it exists
func (ct *connectionTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
delete(ct.connections, id)
}
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id"
"reflect" "reflect"
"testing" "testing"
"time" "time"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id"
) )
func TestE2ESendReport_JSON(t *testing.T) { func TestE2ESendReport_JSON(t *testing.T) {
......
package bindings
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/connect"
"sync"
)
// connectionTracker is a singleton used to keep track of extant clients, allowing
// for race condition free passing over the bindings
type connectionTracker struct {
connections map[int]*Connection
count int
mux sync.RWMutex
}
// make makes a client from an API client, assigning it a unique ID
func (ct *connectionTracker) make(c connect.Connection) *Connection {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.connections[id] = &Connection{
connection: c,
id: id,
}
return ct.connections[id]
}
//get returns a client given its ID
func (ct *connectionTracker) get(id int) (*Connection, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
c, exist := ct.connections[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
//deletes a client if it exists
func (ct *connectionTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
delete(ct.connections, id)
}
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/cmix"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"time"
) )
// Example marshalled roundList object: // Example marshalled roundList object:
......
//////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation / // Copyright © 2020 xx network SEZC //
// / // //
// All rights reserved. / // Use of this source code is governed by a license that can be found in the //
//////////////////////////////////////////////////////////////////////////////// // LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"sync"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/client/xxdk"
...@@ -180,3 +184,51 @@ func (a *authCallback) Reset(partner contact.Contact, ...@@ -180,3 +184,51 @@ func (a *authCallback) Reset(partner contact.Contact,
receptionID receptionID.EphemeralIdentity, round rounds.Round, _ *xxdk.E2e) { receptionID receptionID.EphemeralIdentity, round rounds.Round, _ *xxdk.E2e) {
a.bindingsCbs.Reset(convertAuthCallbacks(partner, receptionID, round)) a.bindingsCbs.Reset(convertAuthCallbacks(partner, receptionID, round))
} }
// e2eTracker is a singleton used to keep track of extant E2e objects,
// preventing race conditions created by passing it over the bindings
type e2eTracker struct {
// TODO: Key on Identity.ID to prevent duplication
clients map[int]*E2e
count int
mux sync.RWMutex
}
// make a E2e from an xxdk.E2e, assigns it a unique ID,
// and adds it to the e2eTracker
func (ct *e2eTracker) make(c *xxdk.E2e) *E2e {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.clients[id] = &E2e{
api: c,
id: id,
}
return ct.clients[id]
}
// get an E2e from the e2eTracker given its ID
func (ct *e2eTracker) get(id int) (*E2e, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
c, exist := ct.clients[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
// delete an E2e if it exists in the e2eTracker
func (ct *e2eTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
delete(ct.clients, id)
}
//////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation / // Copyright © 2020 xx network SEZC //
// / // //
// All rights reserved. / // Use of this source code is governed by a license that can be found in the //
//////////////////////////////////////////////////////////////////////////////// // LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package bindings
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/xxdk"
"sync"
)
// e2eTracker is a singleton used to keep track of extant E2e objects,
// preventing race conditions created by passing it over the bindings
type e2eTracker struct {
// TODO: Key on Identity.ID to prevent duplication
clients map[int]*E2e
count int
mux sync.RWMutex
}
// make a E2e from an xxdk.E2e, assigns it a unique ID,
// and adds it to the e2eTracker
func (ct *e2eTracker) make(c *xxdk.E2e) *E2e {
ct.mux.Lock()
defer ct.mux.Unlock()
id := ct.count
ct.count++
ct.clients[id] = &E2e{
api: c,
id: id,
}
return ct.clients[id]
}
// get an E2e from the e2eTracker given its ID
func (ct *e2eTracker) get(id int) (*E2e, error) {
ct.mux.RLock()
defer ct.mux.RUnlock()
c, exist := ct.clients[id]
if !exist {
return nil, errors.Errorf("Cannot get client for id %d, client "+
"does not exist", id)
}
return c, nil
}
// delete an E2e if it exists in the e2eTracker
func (ct *e2eTracker) delete(id int) {
ct.mux.Lock()
defer ct.mux.Unlock()
delete(ct.clients, id)
}
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"time"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/fileTransfer" "gitlab.com/elixxir/client/fileTransfer"
ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" ftCrypto "gitlab.com/elixxir/crypto/fileTransfer"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"time"
) )
/* File Transfer Structs and Interfaces */ /* File Transfer Structs and Interfaces */
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"testing"
"gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/elixxir/crypto/fileTransfer"
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"testing"
) )
func TestFileTransfer_inputs(t *testing.T) { func TestFileTransfer_inputs(t *testing.T) {
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"fmt" "fmt"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"time"
) )
// StartNetworkFollower kicks off the tracking of the network. It starts // StartNetworkFollower kicks off the tracking of the network. It starts
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/fact"
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"testing"
"gitlab.com/elixxir/crypto/cmix" "gitlab.com/elixxir/crypto/cmix"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
dh "gitlab.com/elixxir/crypto/diffieHellman" dh "gitlab.com/elixxir/crypto/diffieHellman"
...@@ -9,7 +18,6 @@ import ( ...@@ -9,7 +18,6 @@ import (
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"testing"
) )
func TestIdentity_JSON(t *testing.T) { func TestIdentity_JSON(t *testing.T) {
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/e2e/receive" "gitlab.com/elixxir/client/e2e/receive"
) )
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"encoding/json" "encoding/json"
"testing"
"time"
"gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"testing"
"time"
) )
func TestMessage_Json(t *testing.T) { func TestMessage_Json(t *testing.T) {
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
// logging.go contains bindings log control functions
package bindings package bindings
import ( import (
"fmt" "fmt"
"log"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"google.golang.org/grpc/grpclog" "google.golang.org/grpc/grpclog"
"log"
) )
// sets level of logging. All logs the set level and above will be displayed // sets level of logging. All logs the set level and above will be displayed
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import "gitlab.com/elixxir/client/xxdk" import "gitlab.com/elixxir/client/xxdk"
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings package bindings
import ( import (
"fmt" "fmt"
"strings"
"testing"
"gitlab.com/elixxir/comms/testkeys" "gitlab.com/elixxir/comms/testkeys"
"gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"gitlab.com/xx_network/primitives/utils" "gitlab.com/xx_network/primitives/utils"
"strings"
"testing"
) )
var testCert = `-----BEGIN CERTIFICATE----- var testCert = `-----BEGIN CERTIFICATE-----
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment