Skip to content
Snippets Groups Projects
Commit ed54a3ff authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

more bindings work

parent 35605feb
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,8 @@ package bindings
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/xx_network/primitives/id"
"time"
)
......@@ -126,25 +128,49 @@ func (c *Client) RegisterNetworkHealthCB(nhc NetworkHealthCallback) {
// RegisterListener records and installs a listener for messages
// matching specific uid, msgType, and/or username
func (c *Client) RegisterListener(uid []byte, msgType int,
username string, listener Listener) {
listener Listener) (ListenerID, error) {
name := listener.Name()
u, err := id.Unmarshal(uid)
if err != nil {
return ListenerID{}, err
}
mt := message.Type(msgType)
f := func(item message.Receive) {
listener.Hear(item)
}
lid := c.api.GetSwitchboard().RegisterFunc(name, u, mt, f)
return ListenerID{id: lid}, nil
}
// Unregister removes the listener with the specified ID so it will no
// longer get called
func (c *Client) UnregisterListener(lid ListenerID) {
c.api.GetSwitchboard().Unregister(lid.id)
}
// RegisterRoundEventsHandler registers a callback interface for round
// events.
func (c *Client) RegisterRoundEventsHandler(hdlr RoundEventHandler) {
}
/*
// SearchWithHandler is a non-blocking search that also registers
// a callback interface for user disovery events.
func (b *BindingsClient) SearchWithHandler(data, separator string,
func (c *Client) SearchWithHandler(data, separator string,
searchTypes []byte, hdlr UserDiscoveryHandler) {
}
// RegisterAuthEventsHandler registers a callback interface for channel
// authentication events.
func (b *BindingsClient) RegisterAuthEventsHandler(hdlr AuthEventHandler) {
}
// RegisterRoundEventsHandler registers a callback interface for round
// events.
func (b *BindingsClient) RegisterRoundEventsHandler(hdlr RoundEventHandler) {
}
// SendE2E sends an end-to-end payload to the provided recipient with
// the provided msgType. Returns the list of rounds in which parts of
......
......@@ -6,11 +6,6 @@
package bindings
import (
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/xx_network/primitives/id"
)
// Client is defined inside the api package. At minimum, it implements all of
// functionality defined here. A Client handles all network connectivity, key
// generation, and storage for a given cryptographic identity on the cmix
......@@ -119,7 +114,7 @@ type client interface {
// GetUser returns the current user Identity for this client. This
// can be serialized into a byte stream for out-of-band sharing.
GetUser() (interfaces.Contact, error)
GetUser() (Contact, error)
// ----- User Discovery -----
......@@ -138,7 +133,7 @@ type client interface {
// so this user can send messages to the desired recipient Contact.
// To receive confirmation from the remote user, clients must
// register a listener to do that.
CreateAuthenticatedChannel(recipient interfaces.Contact, payload []byte) error
CreateAuthenticatedChannel(recipient Contact, payload []byte) error
// RegierAuthEventsHandler registers a callback interface for channel
// authentication events.
RegisterAuthEventsHandler(hdlr AuthEventHandler)
......@@ -155,22 +150,12 @@ type ContactList interface {
// GetLen returns the number of contacts in the list
GetLen() int
// GetContact returns the contact at index i
GetContact(i int) interfaces.Contact
GetContact(i int) Contact
}
// ----- Callback interfaces -----
// Listener provides a callback to hear a message
// An object implementing this interface can be called back when the client
// gets a message of the type that the regi sterer specified at registration
// time.
type Listener interface {
// Hear is called to receive a message in the UI
Hear(payload []byte, mType int, sender []byte, timestamp)
// Returns a name, used for debugging
Name() string
}
// AuthEventHandler handles authentication requests initiated by
// CreateAuthenticatedChannel
......@@ -179,13 +164,13 @@ type AuthEventHandler interface {
// the client has called CreateAuthenticatedChannel for
// the provided contact. Payload is typically empty but
// may include a small introductory message.
HandleConfirmation(contact interfaces.Contact, payload []byte)
HandleConfirmation(contact Contact, payload []byte)
// HandleRequest handles AuthEvents received before
// the client has called CreateAuthenticatedChannel for
// the provided contact. It should prompt the user to accept
// the channel creation "request" and, if approved,
// call CreateAuthenticatedChannel for this Contact.
HandleRequest(contact interfaces.Contact, payload []byte)
HandleRequest(contact Contact, payload []byte)
}
// RoundList contains a list of contacts
......@@ -209,3 +194,57 @@ type UserDiscoveryHandler interface {
type NetworkHealthCallback interface {
Callback(bool)
}
// Message is a message received from the cMix network in the clear
// or that has been decrypted using established E2E keys.
type Message interface {
//Returns the id of the message
GetID() []byte
// Returns the message's sender ID, if available
GetSender() []byte
// Returns the message payload/contents
// Parse this with protobuf/whatever according to the message type
GetPayload() []byte
// Returns the message's type
GetMessageType() int
// Returns the message's timestamp in milliseconds since unix epoc
GetTimestampMS() int
// Returns the message's timestamp in ns since unix epoc
GetTimestampNano() int
}
type Contact interface {
GetID() []byte
GetDHPublicKey() []byte
GetOwnershipProof() []byte
GetFactList() FactList
Marshal() ([]byte, error)
}
type FactList interface {
Num() int
Get(int) Fact
Add(string, int) error
}
type Fact interface {
Get() string
Type() int
}
type User interface {
GetID() []byte
GetSalt() []byte
GetRSAPrivateKeyPem() []byte
GetRSAPublicKeyPem() []byte
IsPrecanned() bool
GetCmixDhPrivateKey() []byte
GetCmixDhPublicKey() []byte
GetE2EDhPrivateKey() []byte
GetE2EDhPublicKey() []byte
GetContact() Contact
}
\ No newline at end of file
package bindings
import "gitlab.com/elixxir/client/switchboard"
// Listener provides a callback to hear a message
// An object implementing this interface can be called back when the client
// gets a message of the type that the regi sterer specified at registration
// time.
type Listener interface {
// Hear is called to receive a message in the UI
Hear(message Message)
// Returns a name, used for debugging
Name() string
}
// id object returned when a listener is created and is used to delete it from
// the system. Beyond calling unregister it has no uses.
type ListenerID struct {
id switchboard.ListenerID
}
func (lid ListenerID) GetUserID() []byte {
return lid.id.GetUserID().Bytes()
}
func (lid ListenerID) GetMessageType() int {
return int(lid.id.GetMessageType())
}
func (lid ListenerID) GetName() string {
return lid.id.GetName()
}
package bindings
import "gitlab.com/elixxir/client/interfaces/message"
// Message is a message received from the cMix network in the clear
// or that has been decrypted using established E2E keys.
type Message interface {
//Returns the id of the message
GetID() []byte
// Returns the message's sender ID, if available
GetSender() []byte
// Returns the message payload/contents
// Parse this with protobuf/whatever according to the message type
GetPayload() []byte
// Returns the message's type
GetMessageType() int
// Returns the message's timestamp in milliseconds since unix epoc
GetTimestampMS() int
// Returns the message's timestamp in ns since unix epoc
GetTimestampNano() int
}
type messageInternal struct {
m message.Receive
}
//Returns the id of the message
func (mi messageInternal) GetID() []byte {
return mi.m.ID[:]
}
// Returns the message's sender ID, if available
func (mi messageInternal) GetSender() []byte {
return mi.m.Sender.Bytes()
}
// Returns the message's payload/contents
func (mi messageInternal) GetPayload() []byte {
return mi.m.Payload
}
// Returns the message's type
func (mi messageInternal) GetMessageType() int {
return int(mi.m.MessageType)
}
// Returns the message's timestamp in ms
func (mi messageInternal) GetTimestampMS() int {
return int(mi.m.Timestamp.Unix())
}
func (mi messageInternal) GetTimestampNano() int {
return int(mi.m.Timestamp.UnixNano())
}
package interfaces
type Contact interface {
GetID() []byte
GetDHPublicKey() []byte
GetOwnershipProof() []byte
GetFactList() FactList
Marshal() ([]byte, error)
}
type FactList interface {
Num() int
Get(int) Fact
Add(string, int) error
}
type Fact interface {
Get() string
Type() int
}
......@@ -3,7 +3,7 @@ package contact
import (
"encoding/json"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/bindings"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/xx_network/primitives/id"
)
......@@ -34,7 +34,7 @@ func (c Contact) GetOwnershipProof() []byte {
}
// Returns a fact list for adding and getting facts to and from the contact
func (c Contact) GetFactList() interfaces.FactList {
func (c Contact) GetFactList() bindings.FactList {
return FactList{source: &c}
}
......
......@@ -2,7 +2,7 @@ package contact
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/bindings"
)
type FactList struct {
......@@ -13,7 +13,7 @@ func (fl FactList) Num() int {
return len(fl.source.Facts)
}
func (fl FactList) Get(i int) interfaces.Fact {
func (fl FactList) Get(i int) bindings.Fact {
return fl.source.Facts[i]
}
......
......@@ -7,10 +7,39 @@ import (
)
type Receive struct {
ID e2e.MessageID
Payload []byte
MessageType Type
Sender *id.ID
Timestamp time.Time
Encryption EncryptionType
ID e2e.MessageID
}
//Returns the id of the message
func (r Receive) GetID() []byte {
return r.ID[:]
}
// Returns the message's sender ID, if available
func (r Receive) GetSender() []byte {
return r.Sender.Bytes()
}
// Returns the message's payload/contents
func (r Receive) GetPayload() []byte {
return r.Payload
}
// Returns the message's type
func (r Receive) GetMessageType() int {
return int(r.MessageType)
}
// Returns the message's timestamp in ms
func (r Receive) GetTimestampMS() int {
return int(r.Timestamp.Unix())
}
func (r Receive) GetTimestampNano() int {
return int(r.Timestamp.UnixNano())
}
\ No newline at end of file
package interfaces
type User interface {
GetID() []byte
GetSalt() []byte
GetRSAPrivateKeyPem() []byte
GetRSAPublicKeyPem() []byte
IsPrecanned() bool
GetCmixDhPrivateKey() []byte
GetCmixDhPublicKey() []byte
GetE2EDhPrivateKey() []byte
GetE2EDhPublicKey() []byte
GetContact() Contact
}
package user
import (
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/bindings"
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/xx_network/crypto/signature/rsa"
......@@ -60,7 +60,7 @@ func (u User) GetE2EDhPublicKey() []byte {
return u.E2eDhPublicKey.Bytes()
}
func (u User) GetContact() interfaces.Contact {
func (u User) GetContact() bindings.Contact {
return contact.Contact{
ID: u.ID.DeepCopy(),
DhPubKey: u.E2eDhPublicKey,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment