diff --git a/bindings/connect.go b/bindings/connect.go index c30a64e016e372971a271af8497cbb1ef39d7d29..05bfd2afe5394f7bd517e96326e01d0f0ebcd929 100644 --- a/bindings/connect.go +++ b/bindings/connect.go @@ -5,28 +5,31 @@ import ( "gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/connect" e2e2 "gitlab.com/elixxir/client/e2e" - contact2 "gitlab.com/elixxir/crypto/contact" - "gitlab.com/elixxir/crypto/e2e" - "gitlab.com/xx_network/primitives/id" - "time" + "gitlab.com/elixxir/client/e2e/ratchet/partner" + "gitlab.com/elixxir/client/e2e/receive" + "gitlab.com/elixxir/crypto/contact" ) //connection tracker singleton, used to track connections so they can be //referenced by id back over the bindings var connectionTrackerSingleton = &connectionTracker{ - connections: make(map[int]Connection), + connections: make(map[int]*Connection), count: 0, } +// type Connection struct { - connection connect.Connection + connection connect.AuthenticatedConnection id int } -// Connect blocks until it connects to the remote +// Connect performs auth key negotiation with the given recipient, +// and returns a Connection object for the newly-created partner.Manager +// This function is to be used sender-side and will block until the +// partner.Manager is confirmed. func (c *Client) Connect(recipientContact []byte, myIdentity []byte) ( *Connection, error) { - cont, err := contact2.Unmarshal(recipientContact) + cont, err := contact.Unmarshal(recipientContact) if err != nil { return nil, err } @@ -45,12 +48,32 @@ func (c *Client) Connect(recipientContact []byte, myIdentity []byte) ( return connectionTrackerSingleton.make(connection), nil } +// ConnectWithAuthentication is called by the client, ie the one establishing +// connection with the server. Once a connect.Connection has been established +// with the server and then authenticate their identity to the server. +func (c *Client) ConnectWithAuthentication(recipientContact []byte, myIdentity []byte) (*Connection, error) { + cont, err := contact.Unmarshal(recipientContact) + if err != nil { + return nil, err + } + myID, rsaPriv, salt, myDHPriv, err := unmarshalIdentity(myIdentity) + if err != nil { + return nil, err + } + + connection, err := connect.ConnectWithAuthentication(cont, myID, salt, rsaPriv, myDHPriv, c.api.GetRng(), + c.api.GetStorage().GetE2EGroup(), c.api.GetCmix(), connect.GetDefaultParams()) + return connectionTrackerSingleton.make(connection), nil +} + +// type E2ESendReport struct { roundsList MessageID []byte Timestamp int64 } +// SendE2E is a wrapper for sending specifically to the Connection's partner.Manager func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) { rounds, mid, ts, err := c.connection.SendE2E(catalog.MessageType(mt), payload, e2e2.GetDefaultParams()) @@ -68,3 +91,24 @@ func (c *Connection) SendE2E(mt int, payload []byte) ([]byte, error) { return json.Marshal(&sr) } + +// Close deletes this Connection's partner.Manager and releases resources +func (c *Connection) Close() { + c.Close() +} + +// GetPartner returns the partner.Manager for this Connection +func (c *Connection) GetPartner() partner.Manager { + +} + +// RegisterListener is used for E2E reception +// and allows for reading data sent from the partner.Manager +func (c *Connection) RegisterListener(messageType int, newListener receive.Listener) receive.ListenerID { + +} + +// Unregister listener for E2E reception +func (c *Connection) Unregister(listenerID receive.ListenerID) { + +} diff --git a/bindings/connectionTracker.go b/bindings/connectionTracker.go index 19573ed4e3550a30c4e5d31d997abdc8de2b8bd3..0352c3285acee4b64b0bc951898ba3f4991e6d04 100644 --- a/bindings/connectionTracker.go +++ b/bindings/connectionTracker.go @@ -6,14 +6,6 @@ import ( "sync" ) -package bindings - -import ( -"github.com/pkg/errors" -"gitlab.com/elixxir/client/api" -"sync" -) - // connectionTracker is a singleton used to keep track of extant clients, allowing // for race condition free passing over the bindings diff --git a/bindings/restlike.go b/bindings/restlike.go new file mode 100644 index 0000000000000000000000000000000000000000..9d713441c2fd35e77d8d7c3a09c1d5666b4c78d0 --- /dev/null +++ b/bindings/restlike.go @@ -0,0 +1,7 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2022 Privategrity Corporation / +// / +// All rights reserved. / +//////////////////////////////////////////////////////////////////////////////// + +package bindings