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

Add stringer interface for message processors. SendUnsafe and precan E2E are now working

parent 3b99642b
No related branches found
No related tags found
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
......@@ -3,6 +3,7 @@ package auth
import (
"encoding/base64"
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth/store"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
......@@ -109,3 +110,9 @@ func (rcs *receivedConfirmService) Process(msg format.Message,
}
state.callbacks.Confirm(c, receptionID, round)
}
func (rcs *receivedConfirmService) String() string {
return fmt.Sprintf("authConfirm(%s, %s, %s)",
rcs.s.e2e.GetReceptionID(), rcs.GetPartner(),
rcs.GetFingerprint())
}
......@@ -3,6 +3,8 @@ package auth
import (
"encoding/base64"
"fmt"
"strings"
"github.com/cloudflare/circl/dh/sidh"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
......@@ -15,7 +17,6 @@ import (
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
"strings"
)
const dummyerr = "dummy error so we dont delete the request"
......@@ -248,6 +249,11 @@ func (rrs *receivedRequestService) Process(message format.Message,
}
}
func (rrs *receivedRequestService) String() string {
return fmt.Sprintf("authRequest(%s)",
rrs.s.e2e.GetReceptionID())
}
func processDecryptedMessage(b []byte) (*id.ID, *sidh.PublicKey, fact.FactList,
[]byte, error) {
//decode the ecr format
......
......@@ -74,7 +74,7 @@ func (a *authCallbacks) Reset(requestor contact.Contact,
func registerMessageListener(client *api.Client) chan receive.Message {
recvCh := make(chan receive.Message, 10000)
listenerID := client.RegisterListenerChannel("DefaultCLIReceiver",
receive.AnyUser(), catalog.XxMessage, recvCh)
receive.AnyUser(), catalog.NoType, recvCh)
jww.INFO.Printf("Message ListenerID: %v", listenerID)
return recvCh
}
......@@ -211,6 +211,7 @@ var rootCmd = &cobra.Command{
recipientContact = user.GetContact()
}
client.GetE2EHandler().EnableUnsafeReception()
recvCh := registerMessageListener(client)
err := client.StartNetworkFollower(5 * time.Second)
......
......@@ -9,11 +9,12 @@ package message
import (
"fmt"
"sync"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/netTime"
"sync"
)
func (p *handler) handleMessages(stop *stoppable.Single) {
......@@ -28,6 +29,8 @@ func (p *handler) handleMessages(stop *stoppable.Single) {
wg.Add(len(bundle.Messages))
for i := range bundle.Messages {
msg := bundle.Messages[i]
jww.TRACE.Printf("handle IterMsgs: %s",
msg.Digest())
go func() {
count, ts := p.inProcess.Add(
......@@ -68,8 +71,12 @@ func (p *handler) handleMessage(ecrMsg format.Message, bundle Bundle) bool {
identity := bundle.Identity
round := bundle.RoundInfo
jww.INFO.Printf("handleMessage(%s)", ecrMsg.Digest())
// If we have a fingerprint, process it
if proc, exists := p.pop(identity.Source, fingerprint); exists {
jww.DEBUG.Printf("handleMessage found fingerprint: %s",
ecrMsg.Digest())
proc.Process(ecrMsg, identity, round)
return true
}
......@@ -78,6 +85,8 @@ func (p *handler) handleMessage(ecrMsg format.Message, bundle Bundle) bool {
identity.Source, ecrMsg.GetSIH(), ecrMsg.GetContents())
if exists {
for _, t := range services {
jww.DEBUG.Printf("handleMessage service found: %s, %s",
ecrMsg.Digest(), t)
go t.Process(ecrMsg, identity, round)
}
if len(services) == 0 {
......
package message
import (
"gitlab.com/elixxir/client/cmix/rounds"
"fmt"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/primitives/format"
)
......@@ -16,4 +18,7 @@ type Processor interface {
// and can lead to compromise of message contents and integrity.
Process(message format.Message, receptionID receptionID.EphemeralIdentity,
round rounds.Round)
// Implement the stringer interface String() string for debugging
fmt.Stringer
}
......@@ -78,25 +78,32 @@ func (sm *ServicesManager) get(clientID *id.ID, receivedSIH,
if !exists {
return nil, false
}
// NOTE: We exit on the first service match
for _, s := range services {
// Check if the SIH matches this service
if s.ForMe(ecrMsgContents, receivedSIH) {
if s.defaultList == nil && s.Tag != sih.Default {
//skip if the processor is nil
if s.Processor != nil {
if s.Processor == nil {
jww.ERROR.Printf("<nil> processor: %s",
s.Tag)
return []Processor{}, true
}
// Return this service directly if not the default service
// Return this service directly if not
// the default service
return []Processor{s}, true
} else if s.defaultList != nil {
// If it is default and the default list is not empty, then
// return the default list
// If it is default and the default
// list is not empty, then return the
// default list
return s.defaultList, true
}
// Return false if it is for me, but I have nothing registered to
// respond to default queries
// Return false if it is for me, but I have
// nothing registered to respond to default
// queries
return []Processor{}, false
}
}
......@@ -198,3 +205,7 @@ func (sm *ServicesManager) DeleteClientService(clientID *id.ID) {
delete(sm.tmap, *clientID)
}
func (s service) String() string {
return s.Service.String()
}
package e2e
import (
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/e2e/ratchet/partner/session"
"gitlab.com/elixxir/primitives/format"
)
......@@ -37,3 +39,8 @@ func (p *processor) Process(ecrMsg format.Message,
p.m.Switchboard.Speak(message)
}
}
func (p *processor) String() string {
return fmt.Sprintf("E2E(%s): %s",
p.m.myID, p.cy.GetSession())
}
......@@ -62,6 +62,9 @@ func (m *manager) sendUnsafe(mt catalog.MessageType, recipient *id.ID,
unencryptedMAC, fp := e2e.SetUnencrypted(payload,
m.myID)
jww.TRACE.Printf("sendUnsafe contents: %v, fp: %v, mac: %v",
payload, fp, unencryptedMAC)
var err error
roundIds[i], _, err = m.net.Send(recipient, fp,
srvc, payload, unencryptedMAC,
......
package e2e
import (
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format"
)
......@@ -17,7 +19,14 @@ func (up *UnsafeProcessor) Process(ecrMsg format.Message,
receptionID receptionID.EphemeralIdentity,
round rounds.Round) {
//check if the message is unencrypted
jww.INFO.Printf("Unsafe PRocessed received: contents: %v, fp: %v, mac: %v, sih: %v",
ecrMsg.GetContents(), ecrMsg.GetKeyFP(), ecrMsg.GetMac(), ecrMsg.GetSIH())
unencrypted, sender := e2e.IsUnencrypted(ecrMsg)
if !unencrypted && sender == nil {
jww.ERROR.Printf("unencrypted message failed MAC check: %v",
ecrMsg)
return
}
if !unencrypted {
jww.ERROR.Printf("Received a non unencrypted message in e2e "+
"service %s, A message might have dropped!", up.tag)
......@@ -35,3 +44,7 @@ func (up *UnsafeProcessor) Process(ecrMsg format.Message,
up.m.Switchboard.Speak(message)
}
}
func (up *UnsafeProcessor) String() string {
return fmt.Sprintf("Unsafe(%s)", up.m.myID)
}
......@@ -8,6 +8,8 @@
package fileTransfer
import (
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
......@@ -62,3 +64,7 @@ func (p *processor) Process(msg format.Message,
// Call callback with updates
p.callbacks.Call(p.TransferID(), nil)
}
func (p *processor) String() string {
return fmt.Sprintf("FileTransfer(%s)", p.myID)
}
......@@ -8,6 +8,9 @@
package groupChat
import (
"fmt"
"time"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
......@@ -16,7 +19,6 @@ import (
"gitlab.com/elixxir/crypto/group"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/states"
"time"
)
// Error messages.
......@@ -77,6 +79,10 @@ func (p *receptionProcessor) Process(message format.Message, receptionID recepti
p.m.receiveFunc(result)
}
func (p *receptionProcessor) String() string {
return fmt.Sprintf("GroupChatReception(%s)", p.m.receptionId)
}
// decryptMessage decrypts the group message payload and returns its message ID,
// timestamp, sender ID, and message contents.
func decryptMessage(g gs.Group, fingerprint format.Fingerprint, key group.CryptKey, payload []byte) (
......
package single
import (
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
......@@ -119,3 +121,7 @@ func (l *listener) Stop() {
}
l.net.DeleteService(l.myId, svc, l)
}
func (l *listener) String() string {
return fmt.Sprintf("SingleUse(%s)", l.myId)
}
package single
import (
"fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
......@@ -48,3 +50,8 @@ func (rsp *responseProcessor) Process(ecrMsg format.Message,
rsp.callback(payload, receptionID, round, nil)
}
}
func (rsp *responseProcessor) String() string {
return fmt.Sprintf("SingleUseFP(%s, %s)",
rsp.sendingID, rsp.recipient.ID)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment