]> Cypherpunks.ru repositories - govpn.git/commitdiff
Ability to bind human readable name to the peer
authorSergey Matveev <stargrave@stargrave.org>
Thu, 30 Apr 2015 13:49:04 +0000 (16:49 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 30 Apr 2015 13:49:04 +0000 (16:49 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
doc/user.texi
identify.go
utils/newclient.sh

index dbbda98c8c8900fa475ed609829f85cc46cd5770..b177e754de40effaf88ac42ab9d6aa55d6fa0083 100644 (file)
@@ -34,8 +34,10 @@ or terminated.
 Server needs to know only the address to listen on and path to directory
 containing peers information. This directory must contain subdirectories
 with the names equal to client's identifications. Each of them must have
-key file with corresponding authentication key, up.sh script that has to
-print interface's name on the first line and optional down.sh.
+@strong{key} file with corresponding authentication key, @strong{up.sh}
+script that has to print interface's name on the first output line.
+Optionally there can be @code{down.sh} that will be executed when client
+disconnects, and @code{name} file containing human readable client's name.
 
 @menu
 * Example usage::
@@ -61,20 +63,19 @@ convenience.
 
 @example
 % ./utils/newclient.sh Alice
-peers/9b40701bdaf522f2b291cb039490312/Alice
+9b40701bdaf522f2b291cb039490312
 @end example
 
 @code{9b40701bdaf522f2b291cb039490312} is client's identification.
-@code{Alice} is just an empty file that can help to search them like
-this: @verb{|find peers -name Alice|}. @code{key} file inside peer's
-directory contains authentication key.
+@code{peers/9b40701bdaf522f2b291cb039490312/name} contains @emph{Alice},
+@code{peers/9b40701bdaf522f2b291cb039490312/key} contains authentication key and
+@code{peers/9b40701bdaf522f2b291cb039490312/up.sh} contains currently
+dummy empty up-script.
 
 GNU/Linux IPv4 client-server example:
 
 @example
-server% echo "#!/bin/sh" > peers/CLIENTID/up.sh
 server% echo "echo tap10" >> peers/CLIENTID/up.sh
-server% chmod 500 peers/CLIENTID/up.sh
 server% ip addr add 192.168.0.1/24 dev wlan0
 server% tunctl -t tap10
 server% ip link set mtu 1462 dev tap10
@@ -107,7 +108,6 @@ $tap=$(ifconfig tap create)
 ifconfig $tap inet6 fc00::1/96 mtu 1462 up
 echo $tap
 EOF
-server% chmod 500 peers/CLIENTID/up.sh
 server% ifconfig em0 inet6 fe80::1/64
 server% GOMAXPROC=4 govpn-server -bind fe80::1%em0
 @end example
index e4baea14c5f89b45bc0b8dcaeeabaa4a63ac8c07..6c16da08a2a3c1cc124f0b0995b99142e24aad59 100644 (file)
@@ -21,8 +21,11 @@ package govpn
 import (
        "crypto/subtle"
        "encoding/hex"
+       "io/ioutil"
        "log"
        "os"
+       "path"
+       "strings"
        "sync"
        "time"
 
@@ -40,6 +43,16 @@ func (id PeerId) String() string {
        return hex.EncodeToString(id[:])
 }
 
+// Return human readable name of the peer.
+// It equals either to peers/PEER/name file contents or PEER's hex.
+func (id PeerId) MarshalJSON() ([]byte, error) {
+       result := id.String()
+       if name, err := ioutil.ReadFile(path.Join(PeersPath, result, "name")); err == nil {
+               result = strings.TrimRight(string(name), "\n")
+       }
+       return []byte(`"` + result + `"`), nil
+}
+
 type cipherCache map[PeerId]*xtea.Cipher
 
 var (
index 620aac71538a6240294a4c7adc24f2577c5994c6..68469b66aa63047f9019937506dc9d2087ba3c7a 100755 (executable)
@@ -9,8 +9,8 @@ getrand()
 [ -n "$1" ] || {
     cat <<EOF
 Example script for creating new user peer for GoVPN.
-It just creates directory with random peer ID and random key in it,
-and adds empty file with human readable username.
+It just creates directory with random peer ID, random key,
+saves username in it and creates dummy up.sh executable script.
 
 Usage: $0 <username>
 EOF
@@ -22,5 +22,7 @@ peerid=$(getrand 16)
 umask 077
 mkdir -p peers/$peerid
 getrand 32 > peers/$peerid/key
-touch peers/$peerid/$1
-echo peers/$peerid/$1
+echo $username > peers/$peerid/name
+echo '#!/bin/sh' > peers/$peerid/up.sh
+chmod 700 peers/$peerid/up.sh
+echo $peerid