Skip to content
Snippets Groups Projects
Commit 24773345 authored by Josh Brooks's avatar Josh Brooks
Browse files

Clean up code and fix bug (maybe)

parent 7054b473
Branches
Tags
2 merge requests!510Release,!245Josh/fix ud
......@@ -41,7 +41,8 @@ const (
trackedIDChanSize = 1000
deleteIDChanSize = 1000
// DefaultExtraChecks is the default value for ExtraChecks on receptionID.Identity.
// DefaultExtraChecks is the default value for ExtraChecks
// on receptionID.Identity.
DefaultExtraChecks = 10
)
......@@ -225,8 +226,8 @@ func (t *manager) track(stop *stoppable.Single) {
}
}
// processIdentities builds and adds new identities and removes old identities from the tracker
// and returns the timestamp of the next ID event
// processIdentities builds and adds new identities and removes old
// identities from the tracker and returns the timestamp of the next ID event.
func (t *manager) processIdentities(addressSize uint8) time.Time {
edits := false
toRemove := make(map[int]struct{})
......@@ -304,7 +305,8 @@ func unmarshalTimestamp(lastTimestampObj *versioned.Object) (time.Time, error) {
// generateIdentitiesOverRange generates and adds all not yet existing ephemeral Ids
// and returns the timestamp of the next generation for the given TrackedID
func (t *manager) generateIdentitiesOverRange(inQuestion TrackedID, addressSize uint8) time.Time {
func (t *manager) generateIdentitiesOverRange(inQuestion TrackedID,
addressSize uint8) time.Time {
// Ensure that ephemeral IDs will not be generated after the
// identity is invalid
generateUntil := inQuestion.NextGeneration
......@@ -337,7 +339,8 @@ func (t *manager) generateIdentitiesOverRange(inQuestion TrackedID, addressSize
}
// Move up the end time if the source identity is invalid
// before the natural end of the ephemeral identity
if inQuestion.ValidUntil != Forever && newIdentity.End.After(inQuestion.ValidUntil) {
if inQuestion.ValidUntil != Forever && newIdentity.End.
After(inQuestion.ValidUntil) {
newIdentity.End = inQuestion.ValidUntil
}
......@@ -348,7 +351,8 @@ func (t *manager) generateIdentitiesOverRange(inQuestion TrackedID, addressSize
// Print debug information and set return value
if isLastIdentity := i == len(protoIds)-1; isLastIdentity {
jww.INFO.Printf("Current Identity: %d (source: %s), Start: %s, End: %s, addrSize: %d",
jww.INFO.Printf("Current Identity: %d (source: %s), Start: %s, "+
"End: %s, addrSize: %d",
newIdentity.EphId.Int64(),
newIdentity.Source,
newIdentity.StartValid,
......
......@@ -25,7 +25,8 @@ type receiver struct {
// Callback is the handler for single-use message reception for a RestServer
// Automatically responds to invalid endpoint requests
func (s *receiver) Callback(req *single.Request, receptionId receptionID.EphemeralIdentity, rounds []rounds.Round) {
func (s *receiver) Callback(req *single.Request,
receptionId receptionID.EphemeralIdentity, rounds []rounds.Round) {
// Unmarshal the request payload
newMessage := &restlike.Message{}
err := proto.Unmarshal(req.GetPayload(), newMessage)
......@@ -35,7 +36,8 @@ func (s *receiver) Callback(req *single.Request, receptionId receptionID.Ephemer
}
var respondErr error
if cb, err := s.endpoints.Get(restlike.URI(newMessage.GetUri()), restlike.Method(newMessage.GetMethod())); err == nil {
if cb, err := s.endpoints.Get(restlike.URI(newMessage.GetUri()),
restlike.Method(newMessage.GetMethod())); err == nil {
// Send the payload to the proper Callback if it exists and singleRespond with the result
respondErr = singleRespond(cb(newMessage), req)
} else {
......
......@@ -2,7 +2,10 @@ package single
import (
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/message"
cMixMsg "gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
......@@ -10,6 +13,46 @@ import (
"time"
)
// Receiver contains the callback interface for any handler which
// will process the reception of a single request. Used in Listen.
type Receiver interface {
Callback(*Request, receptionID.EphemeralIdentity, []rounds.Round)
}
// Response contains the callback interface for any handler which
// will process the response of a single request. Used in TransmitRequest.
type Response interface {
Callback(payload []byte, receptionID receptionID.EphemeralIdentity,
rounds []rounds.Round, err error)
}
type Listener interface {
// Stop unregisters the listener
Stop()
}
// RequestCmix interface matches a subset of the cmix.Client methods used by the
// Request for easier testing.
type RequestCmix interface {
GetMaxMessageLength() int
Send(recipient *id.ID, fingerprint format.Fingerprint,
service cMixMsg.Service, payload, mac []byte,
cmixParams cmix.CMIXParams) (id.Round, ephemeral.Id, error)
GetInstance() *network.Instance
}
// ListenCmix interface matches a subset of cmix.Client methods used for Listen.
type ListenCmix interface {
RequestCmix
AddFingerprint(identity *id.ID, fingerprint format.Fingerprint,
mp cMixMsg.Processor) error
AddService(
clientID *id.ID, newService cMixMsg.Service, response cMixMsg.Processor)
DeleteService(
clientID *id.ID, toDelete cMixMsg.Service, processor cMixMsg.Processor)
CheckInProgressMessages()
}
// Cmix is a sub-interface of the cmix.Client. It contains the methods relevant
// to what is used in this package.
type Cmix interface {
......
......@@ -16,15 +16,6 @@ import (
"strings"
)
type Receiver interface {
Callback(*Request, receptionID.EphemeralIdentity, []rounds.Round)
}
type Listener interface {
// Stop unregisters the listener
Stop()
}
type listener struct {
tag string
grp *cyclic.Group
......@@ -62,17 +53,6 @@ func Listen(tag string, myID *id.ID, privKey *cyclic.Int, net ListenCmix,
return l
}
type ListenCmix interface {
RequestCmix
AddFingerprint(identity *id.ID, fingerprint format.Fingerprint,
mp cMixMsg.Processor) error
AddService(
clientID *id.ID, newService cMixMsg.Service, response cMixMsg.Processor)
DeleteService(
clientID *id.ID, toDelete cMixMsg.Service, processor cMixMsg.Processor)
CheckInProgressMessages()
}
// Process decrypts and collates the encrypted single-use request message.
func (l *listener) Process(ecrMsg format.Message,
receptionID receptionID.EphemeralIdentity, round rounds.Round) {
......
......@@ -8,14 +8,11 @@ import (
"gitlab.com/elixxir/client/cmix"
cmixMsg "gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/single/message"
"gitlab.com/elixxir/comms/network"
ds "gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/e2e/singleUse"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"sync"
"sync/atomic"
"testing"
......@@ -44,16 +41,6 @@ type Request struct {
net RequestCmix
}
// RequestCmix interface matches a subset of the cmix.Client methods used by the
// Request for easier testing.
type RequestCmix interface {
GetMaxMessageLength() int
Send(recipient *id.ID, fingerprint format.Fingerprint,
service cmixMsg.Service, payload, mac []byte,
cmixParams cmix.CMIXParams) (id.Round, ephemeral.Id, error)
GetInstance() *network.Instance
}
// Respond is used to respond to the request. It sends a payload up to
// Request.GetMaxResponseLength. It will chunk the message into multiple cMix
// messages if it is too long for a single message. It will fail if a single
......
......@@ -23,12 +23,6 @@ import (
"time"
)
// Response interface allows for callbacks to
type Response interface {
Callback(payload []byte, receptionID receptionID.EphemeralIdentity,
rounds []rounds.Round, err error)
}
// Error messages.
const (
// TransmitRequest
......
......@@ -331,6 +331,7 @@ func LoginWithProtoClient(storageDir string, password []byte,
return nil, err
}
c.network.AddIdentity(c.GetUser().ReceptionID, time.Time{}, true)
c.storage.SetNDF(def)
err = c.initPermissioning(def)
......
......@@ -49,9 +49,9 @@ func LoginEphemeral(client *Cmix, callbacks auth.Callbacks,
}
// LoginLegacy creates a new E2e backed by the xxdk.Cmix persistent versioned.KV
// Uses the pre-generated transmission ID used by xxdk.Cmix
// This function is designed to maintain backwards compatibility with previous xx messenger designs
// and should not be used for other purposes
// Uses the pre-generated transmission ID used by xxdk.Cmix.
// This function is designed to maintain backwards compatibility with previous
// xx messenger designs and should not be used for other purposes.
func LoginLegacy(client *Cmix, callbacks auth.Callbacks) (m *E2e, err error) {
m = &E2e{
Cmix: client,
......@@ -82,7 +82,7 @@ func LoginLegacy(client *Cmix, callbacks auth.Callbacks) (m *E2e, err error) {
return m, err
}
// login creates a new e2eApi.E2e backed by the given versioned.KV
// login creates a new xxdk.E2e backed by the given versioned.KV
func login(client *Cmix, callbacks auth.Callbacks,
identity ReceptionIdentity, kv *versioned.KV) (m *E2e, err error) {
......
......@@ -23,8 +23,10 @@ type ReceptionIdentity struct {
DHKeyPrivate *cyclic.Int
}
// MakeReceptionIdentity generates a new cryptographic identity for receiving messages
func MakeReceptionIdentity(rng csprng.Source, grp *cyclic.Group) (ReceptionIdentity, error) {
// MakeReceptionIdentity generates a new cryptographic identity
// for receiving messages.
func MakeReceptionIdentity(rng csprng.Source,
grp *cyclic.Group) (ReceptionIdentity, error) {
//make RSA Key
rsaKey, err := rsa.GenerateKey(rng,
rsa.DefaultRSABitLen)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment