Commit d2e757f3 authored by David Stainton's avatar David Stainton

Make it build with gopy

parent f0598e67
......@@ -18,39 +18,20 @@ package client
import (
"encoding/hex"
"errors"
"fmt"
"github.com/katzenpost/bindings/python/internal"
"github.com/katzenpost/client"
"github.com/katzenpost/core/crypto/ecdh"
"github.com/katzenpost/minclient/block"
"github.com/op/go-logging"
)
// StorageStub implements the Storage interface
// as defined in the client library.
// XXX This should be replaced by something useful.
type StorageStub struct {
}
// GetBlocks returns a slice of blocks
func (s StorageStub) GetBlocks(*[block.MessageIDLength]byte) ([][]byte, error) {
return nil, errors.New("failure: StorageStub GetBlocks not yet implemented")
}
// PutBlock puts a block into storage
func (s StorageStub) PutBlock(*[block.MessageIDLength]byte, []byte) error {
return errors.New("failure: StorageStub PutBlock not yet implemented")
}
// Session holds the client session
type Session struct {
client *client.Client
log *logging.Logger
clientCfg *client.Config
sessionCfg *client.SessionConfig
session *client.Session
ingressMsgQueue chan string
client *client.Client
log *logging.Logger
clientCfg *client.Config
sessionCfg *client.SessionConfig
session *client.Session
}
// NewSession stablishes a session with provider using key
......@@ -69,53 +50,22 @@ func (c Client) NewSession(user string, provider string, key Key) (Session, erro
return session, err
}
session.client = gClient
session.ingressMsgQueue = make(chan string, 100)
session.log = c.log.GetLogger(fmt.Sprintf("session_%s@%s", user, provider))
return session, err
}
// ReceivedMessage is used to receive a message.
// This is a method on the MessageConsumer interface
// which is defined in the client library.
// XXX fix me
func (s Session) ReceivedMessage(senderPubKey *ecdh.PublicKey, message []byte) {
s.log.Debug("ReceivedMessage")
s.ingressMsgQueue <- string(message)
}
// GetMessage blocks until there is a message in the inbox
func (s Session) GetMessage() string {
s.log.Debug("GetMessage")
return <-s.ingressMsgQueue
}
// ReceivedACK is used to receive a signal that a message was received by
// the recipient Provider. This is a method on the MessageConsumer interface
// which is defined in the client library.
// XXX fix me
func (s Session) ReceivedACK(messageID *[block.MessageIDLength]byte, message []byte) {
s.log.Debug("ReceivedACK")
}
// Get returns the identity public key for a given identity.
// This is part of the UserKeyDiscovery interface defined
// in the client library.
// XXX fix me
func (s Session) Get(identity string) (*ecdh.PublicKey, error) {
s.log.Debugf("Get identity %s", identity)
return nil, nil
}
// Connect connects the client to the Provider
func (s Session) Connect(identityKey Key) error {
consumer := internal.NewMessageConsumer(s.log)
userKeyDiscoveryStub := internal.UserKeyDiscoveryStub{}
sessionCfg := client.SessionConfig{
User: s.clientCfg.User,
Provider: s.clientCfg.Provider,
IdentityPrivKey: identityKey.priv,
LinkPrivKey: s.clientCfg.LinkKey,
MessageConsumer: s,
Storage: new(StorageStub),
UserKeyDiscovery: s,
MessageConsumer: consumer,
Storage: new(internal.StorageStub),
UserKeyDiscovery: userKeyDiscoveryStub,
}
s.sessionCfg = &sessionCfg
var err error
......@@ -123,6 +73,10 @@ func (s Session) Connect(identityKey Key) error {
return err
}
func (s Session) GetMessage() string {
return s.sessionCfg.MessageConsumer.(internal.MessageConsumer).GetMessage()
}
// Shutdown the session
func (s Session) Shutdown() {
s.Shutdown()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment