aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/transport/connection.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet/transport/connection.go')
-rw-r--r--src/gnunet/transport/connection.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/gnunet/transport/connection.go b/src/gnunet/transport/connection.go
index e66bec1..1cf0317 100644
--- a/src/gnunet/transport/connection.go
+++ b/src/gnunet/transport/connection.go
@@ -5,7 +5,6 @@ import (
5 "gnunet/message" 5 "gnunet/message"
6) 6)
7 7
8////////////////////////////////////////////////////////////////////////
9// Connection for communicating peers 8// Connection for communicating peers
10type Connection struct { 9type Connection struct {
11 from, to *core.Peer 10 from, to *core.Peer
@@ -17,6 +16,8 @@ type Connection struct {
17 shared []byte 16 shared []byte
18} 17}
19 18
19// NewConnection instanciates a new connection between peers communicating
20// over a message channel (Connections are authenticated and secured).
20func NewConnection(ch *MsgChannel, from, to *core.Peer) *Connection { 21func NewConnection(ch *MsgChannel, from, to *core.Peer) *Connection {
21 return &Connection{ 22 return &Connection{
22 from: from, 23 from: from,
@@ -26,27 +27,33 @@ func NewConnection(ch *MsgChannel, from, to *core.Peer) *Connection {
26 } 27 }
27} 28}
28 29
30// SharedSecret computes the shared secret the two endpoints of a connection.
29func (c *Connection) SharedSecret(secret []byte) { 31func (c *Connection) SharedSecret(secret []byte) {
30 c.shared = make([]byte, len(secret)) 32 c.shared = make([]byte, len(secret))
31 copy(c.shared, secret) 33 copy(c.shared, secret)
32} 34}
33 35
36// GetState returns the current state of the connection.
34func (c *Connection) GetState() int { 37func (c *Connection) GetState() int {
35 return c.state 38 return c.state
36} 39}
37 40
41// SetBandwidth to control transfer rates on the connection
38func (c *Connection) SetBandwidth(bw uint32) { 42func (c *Connection) SetBandwidth(bw uint32) {
39 c.bandwidth = bw 43 c.bandwidth = bw
40} 44}
41 45
46// Close connection between two peers.
42func (c *Connection) Close() error { 47func (c *Connection) Close() error {
43 return c.ch.Close() 48 return c.ch.Close()
44} 49}
45 50
51// Send a message on the connection
46func (c *Connection) Send(msg message.Message) error { 52func (c *Connection) Send(msg message.Message) error {
47 return c.ch.Send(msg) 53 return c.ch.Send(msg)
48} 54}
49 55
56// Receive a message on the connection
50func (c *Connection) Receive() (message.Message, error) { 57func (c *Connection) Receive() (message.Message, error) {
51 return c.ch.Receive() 58 return c.ch.Receive()
52} 59}