-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiptunnel.go
48 lines (36 loc) · 1004 Bytes
/
iptunnel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cjdns
import (
"log"
"net"
"github.com/willeponken/go-cjdns/key"
)
// AddUser adds a new user to the database and allows a new iptunnel connection for the user.
func (c *Conn) AddUser(publicKey *key.Public, ip net.IP) error {
admin := c.Conn
log.Println(ip)
if err := admin.IpTunnel_allowConnection(publicKey, ip); err != nil {
return err
}
log.Printf("User: %s added to cjdns IP tunnel with IP: %s", publicKey.String(), ip.String())
return nil
}
// DelUser looks up the user for the defined public key and deauthenticates the user from the iptunnel.
func (c *Conn) DelUser(publicKey *key.Public) error {
admin := c.Conn
tunnels, err := admin.IpTunnel_listConnections()
if err != nil {
return err
}
for i := range tunnels {
tunnel, err := admin.IpTunnel_showConnection(tunnels[i])
if err != nil {
return err
}
if publicKey.Equal(tunnel.Key) {
if err := admin.IpTunnel_removeConnection(tunnels[i]); err != nil {
return err
}
}
}
return nil
}