Commit b923eaa8 authored by Vincent Breitmoser's avatar Vincent Breitmoser

update java bindings

parent 0d93530a
package client
// client.go - mixnet client
// Copyright (C) 2017 Yawning Angel.
// Copyright (C) 2018 Ruben Pollan.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package katzenpost
import (
"errors"
"time"
"github.com/katzenpost/core/crypto/ecdh"
"github.com/katzenpost/mailproxy"
"github.com/katzenpost/mailproxy/config"
......@@ -20,6 +40,7 @@ type Client struct {
eventSink chan event.Event
}
// New creates a katzenpost client
func New(cfg Config) (Client, error) {
eventSink := make(chan event.Event)
dataDir, err := cfg.getDataDir()
......@@ -53,14 +74,47 @@ func New(cfg Config) (Client, error) {
return Client{cfg.getAddress(), proxy, eventSink}, err
}
// Shutdown the client
func (c Client) Shutdown() {
c.proxy.Shutdown()
c.proxy.Wait()
}
// Shutdown a message into katzenpost
func (c Client) Send(recipient, msg string) error {
var identityKey ecdh.PrivateKey
identityKey.FromBytes(identityKeyBytes)
c.proxy.SetRecipient(recipient, identityKey.PublicKey())
return c.proxy.SendMessage(c.address, recipient, []byte(msg))
}
// Message received from katzenpost
type Message struct {
Sender string
Payload string
}
// GetMessage from katzenpost
func (c Client) GetMessage(timeout int64) (Message, error) {
if timeout == 0 {
ev := <-c.eventSink
return c.handleEvent(ev)
}
select {
case ev := <-c.eventSink:
return c.handleEvent(ev)
case <-time.After(time.Second * time.Duration(timeout)):
return Message{}, errors.New("Timeout")
}
}
func (c Client) handleEvent(ev event.Event) (Message, error) {
switch ev.(type) {
case *event.MessageReceivedEvent:
msg, err := c.proxy.ReceivePop(c.address)
return Message{msg.SenderID, string(msg.Payload)}, err
default:
return Message{}, errors.New("Another event arrived")
}
}
package client
// config.go - mixnet client configuration
// Copyright (C) 2017 Yawning Angel.
// Copyright (C) 2018 Ruben Pollan.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package katzenpost
import (
"fmt"
......@@ -10,6 +27,7 @@ import (
"github.com/katzenpost/mailproxy/config"
)
// Config has the client configuration
type Config struct {
PkiAddress string
PkiKey string
......
......@@ -15,7 +15,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package client
package katzenpost
import (
"encoding/hex"
......
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