]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/common.go
Configure MTU on per-user basis
[govpn.git] / src / govpn / common.go
index fbafd56ab680de6afc61eb50f41890e1ed1babfc..b453ed9be791a0295b49b5dadbee15cab1754bb5 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
@@ -23,14 +23,16 @@ import (
        "os"
        "os/exec"
        "runtime"
+       "time"
 )
 
 const (
        TimeoutDefault = 60
+       MTUMax         = 9000
+       MTUDefault     = 1500 + 14
 )
 
 var (
-       MTU     int
        Version string
 )
 
@@ -52,13 +54,20 @@ func ScriptCall(path, ifaceName string) ([]byte, error) {
        return out, err
 }
 
-// Zero each byte
-func sliceZero(data []byte) {
+// Zero each byte.
+func SliceZero(data []byte) {
        for i := 0; i < len(data); i++ {
-               data[i] = '\x00'
+               data[i] = 0
        }
 }
 
 func VersionGet() string {
        return "GoVPN version " + Version + " built with " + runtime.Version()
 }
+
+func cprCycleCalculate(rate int) time.Duration {
+       if rate == 0 {
+               return time.Duration(0)
+       }
+       return time.Second / time.Duration(rate*(1<<10)/MTUMax)
+}