]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/cmd/govpn-server/tcp.go
EncLess -> Encless for convenience
[govpn.git] / src / govpn / cmd / govpn-server / tcp.go
index c1969faa486d511000103a660e1780278e12a3e7..e3458cb54df74bb97091eac06fd8b5363fccdb67 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"
@@ -52,7 +51,7 @@ func startTCP() {
 
 func handleTCP(conn net.Conn) {
        addr := conn.RemoteAddr().String()
-       buf := make([]byte, govpn.MTU)
+       buf := make([]byte, govpn.EnclessEnlargeSize+2*govpn.MTUMax)
        var n int
        var err error
        var prev int
@@ -62,7 +61,7 @@ func handleTCP(conn net.Conn) {
        var tap *govpn.TAP
        var conf *govpn.PeerConf
        for {
-               if prev == govpn.MTU {
+               if prev == len(buf) {
                        break
                }
                conn.SetReadDeadline(time.Now().Add(time.Duration(govpn.TimeoutDefault) * time.Second))
@@ -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)
+                       tap, err = govpn.TAPListen(ifaceName, peer.MTU)
                        if err != nil {
                                log.Println("Unable to create TAP:", err)
+                               peer = nil
                                break
                        }
                        ps = &PeerState{
@@ -152,12 +153,11 @@ 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 {
-               if prev == govpn.MTU {
+               if prev == len(buf) {
                        break
                }
                conn.SetReadDeadline(time.Now().Add(conf.Timeout))
@@ -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