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