]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/cmd/govpn-server/tcp.go
Raise copyright years
[govpn.git] / src / govpn / cmd / govpn-server / tcp.go
index c1969faa486d511000103a660e1780278e12a3e7..871c42c8399bb0607c361a60e967690d1a16b333 100644 (file)
@@ -1,6 +1,6 @@
 /*
 GoVPN -- simple secure free software virtual private network daemon
-Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@ package main
 
 import (
        "bytes"
-       "encoding/binary"
        "log"
        "net"
        "time"
@@ -72,12 +71,12 @@ func handleTCP(conn net.Conn) {
                        break
                }
                prev += n
-               peerId := govpn.IDsCache.Find(buf[:prev])
+               peerId := idsCache.Find(buf[:prev])
                if peerId == nil {
                        continue
                }
                if hs == nil {
-                       conf = peerId.Conf()
+                       conf = confs[*peerId]
                        if conf == nil {
                                log.Println("Can not get peer configuration:", peerId.String())
                                break
@@ -118,11 +117,13 @@ func handleTCP(conn net.Conn) {
                } else {
                        ifaceName, err := callUp(peer.Id)
                        if err != nil {
+                               peer = nil
                                break
                        }
                        tap, err = govpn.TAPListen(ifaceName)
                        if err != nil {
                                log.Println("Unable to create TAP:", err)
+                               peer = nil
                                break
                        }
                        ps = &PeerState{
@@ -152,8 +153,7 @@ func handleTCP(conn net.Conn) {
        }
 
        nonceExpectation := make([]byte, govpn.NonceSize)
-       binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-       peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+       peer.NonceExpectation(nonceExpectation)
        prev = 0
        var i int
        for {
@@ -182,8 +182,7 @@ func handleTCP(conn net.Conn) {
                        )
                        break
                }
-               binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-               peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+               peer.NonceExpectation(nonceExpectation)
                copy(buf, buf[i+govpn.NonceSize:prev])
                prev = prev - i - govpn.NonceSize
                goto CheckMore