Integration Pre-Release
This commit is contained in:
vanhempi
60450e81ba
commit
1fec260185
12
cmd/main.go
12
cmd/main.go
|
@ -3,6 +3,8 @@ package main
|
|||
import (
|
||||
"crypto/rand"
|
||||
"cwtch.im/tapir"
|
||||
"cwtch.im/tapir/applications"
|
||||
"cwtch.im/tapir/networks/tor"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
|
@ -14,7 +16,7 @@ import (
|
|||
|
||||
// SimpleApp is a trivial implementation of a basic p2p application
|
||||
type SimpleApp struct {
|
||||
tapir.AuthApp
|
||||
applications.AuthApp
|
||||
}
|
||||
|
||||
// NewInstance should always return a new instantiation of the application.
|
||||
|
@ -27,7 +29,7 @@ func (ea SimpleApp) Init(connection *tapir.Connection) {
|
|||
// First run the Authentication App
|
||||
ea.AuthApp.Init(connection)
|
||||
|
||||
if connection.HasCapability(tapir.AuthCapability) {
|
||||
if connection.HasCapability(applications.AuthCapability) {
|
||||
// The code for out simple application (We just send and receive "Hello"
|
||||
connection.Send([]byte("Hello"))
|
||||
message := connection.Expect()
|
||||
|
@ -55,7 +57,7 @@ func main() {
|
|||
|
||||
// Init the Server running the Simple App.
|
||||
var service tapir.Service
|
||||
service = new(tapir.BaseOnionService)
|
||||
service = new(tor.BaseOnionService)
|
||||
service.Init(acn, sk, id)
|
||||
service.Listen(SimpleApp{})
|
||||
}
|
||||
|
@ -67,7 +69,7 @@ func client(acn connectivity.ACN, key ed25519.PublicKey) {
|
|||
pk := ed25519.PublicKey(pubkey)
|
||||
id := identity.InitializeV3("client", &sk, &pk)
|
||||
var client tapir.Service
|
||||
client = new(tapir.BaseOnionService)
|
||||
client = new(tor.BaseOnionService)
|
||||
client.Init(acn, sk, id)
|
||||
cid, _ := client.Connect(utils.GetTorV3Hostname(key), SimpleApp{})
|
||||
|
||||
|
@ -76,7 +78,7 @@ func client(acn connectivity.ACN, key ed25519.PublicKey) {
|
|||
time.Sleep(time.Second * 5)
|
||||
|
||||
conn, _ := client.GetConnection(cid)
|
||||
log.Debugf("Client has Auth: %v", conn.HasCapability(tapir.AuthCapability))
|
||||
log.Debugf("Client has Auth: %v", conn.HasCapability(applications.AuthCapability))
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
4
go.mod
4
go.mod
|
@ -1,6 +1,6 @@
|
|||
module cwtch.im/osp
|
||||
module cwtch.im/tapir
|
||||
|
||||
require (
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.3
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4
|
||||
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
|||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.3 h1:LHnhK9hzkqMY+iEE3TZ0FjZsYal05YDiamKmxDOXuts=
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.3/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4 h1:GWLMJ5jBSIC/gFXzdbbeVz7fIAn2FTgW8+wBci6/3Ek=
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
|
||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
|
||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
|
||||
github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g=
|
||||
|
|
|
@ -162,14 +162,7 @@ func main() {
|
|||
// Init a Client to Connect to the Server
|
||||
go client(acn, pubkey)
|
||||
|
||||
// Init the Server running the Simple App.
|
||||
var service tapir.Service
|
||||
service = new(tor.BaseOnionService)
|
||||
service.Init(acn, sk, id)
|
||||
bf := new(primitives.BloomFilter)
|
||||
bf.Init(256)
|
||||
var ns NotificationsServer
|
||||
service.Listen(ns)
|
||||
rm
|
||||
}
|
||||
|
||||
// Client will Connect and launch it's own Echo App goroutine.
|
||||
|
|
18
service.go
18
service.go
|
@ -22,10 +22,6 @@ type Service interface {
|
|||
WaitForCapabilityOrClose(connectionID string, capability string) (*Connection, error)
|
||||
}
|
||||
|
||||
// MaxLength is a fairly arbitrary number that very much depends on the application and the available bandwidth/server
|
||||
// storage.
|
||||
const MaxLength = 8192
|
||||
|
||||
// Connection defines a Tapir Connection
|
||||
type Connection struct {
|
||||
hostname string
|
||||
|
@ -37,6 +33,7 @@ type Connection struct {
|
|||
ID identity.Identity
|
||||
Outbound bool
|
||||
Closed bool
|
||||
MaxLength int
|
||||
}
|
||||
|
||||
// NewConnection creates a new Connection
|
||||
|
@ -47,6 +44,7 @@ func NewConnection(id identity.Identity, hostname string, outbound bool, conn ne
|
|||
connection.App = app
|
||||
connection.ID = id
|
||||
connection.Outbound = outbound
|
||||
connection.MaxLength = 1024
|
||||
go connection.App.Init(connection)
|
||||
return connection
|
||||
}
|
||||
|
@ -74,12 +72,12 @@ func (c *Connection) Close() {
|
|||
c.conn.Close()
|
||||
}
|
||||
|
||||
// Expect blocks and reads a single Tapir packet (1024 bytes), from the connection.
|
||||
// Expect blocks and reads a single Tapir packet , from the connection.
|
||||
func (c *Connection) Expect() []byte {
|
||||
buffer := make([]byte, MaxLength)
|
||||
buffer := make([]byte, c.MaxLength)
|
||||
n, err := io.ReadFull(c.conn, buffer)
|
||||
|
||||
if n != MaxLength || err != nil {
|
||||
if n != c.MaxLength || err != nil {
|
||||
log.Errorf("[%v -> %v] Wire Error Reading, Read %d bytes, Error: %v", c.hostname, c.ID.Hostname(), n, err)
|
||||
c.conn.Close()
|
||||
c.Closed = true
|
||||
|
@ -113,7 +111,7 @@ func (c *Connection) SetEncryptionKey(key [32]byte) {
|
|||
// Send writes a given message to a Tapir packet (of 1024 bytes in length).
|
||||
func (c *Connection) Send(message []byte) {
|
||||
|
||||
buffer := make([]byte, MaxLength)
|
||||
buffer := make([]byte, c.MaxLength)
|
||||
binary.PutUvarint(buffer[0:2], uint64(len(message)))
|
||||
copy(buffer[2:], message)
|
||||
|
||||
|
@ -125,8 +123,8 @@ func (c *Connection) Send(message []byte) {
|
|||
c.Closed = true
|
||||
}
|
||||
// MaxLength - 40 = MaxLength - 24 nonce bytes and 16 auth tag.
|
||||
encrypted := secretbox.Seal(nonce[:], buffer[0:MaxLength-40], &nonce, &c.key)
|
||||
copy(buffer, encrypted[0:MaxLength])
|
||||
encrypted := secretbox.Seal(nonce[:], buffer[0:c.MaxLength-40], &nonce, &c.key)
|
||||
copy(buffer, encrypted[0:c.MaxLength])
|
||||
}
|
||||
log.Debugf("[%v -> %v] Wire Send %x", c.ID.Hostname(), c.hostname, buffer)
|
||||
_, err := c.conn.Write(buffer)
|
||||
|
|
Ladataan…
Viittaa uudesa ongelmassa