X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fgovpn%2Fegd.go;h=647c2c9623177dcdc3d9866d07e35f0c9735bf64;hb=5a55ad42b9b740659e8e89963403c27f7704e50a;hp=deb92af7406ba43120f613136eb7187f3a539682;hpb=efaad3bf853603c25ae70a5779cce355d1c21016;p=govpn.git diff --git a/src/cypherpunks.ru/govpn/egd.go b/src/cypherpunks.ru/govpn/egd.go index deb92af..647c2c9 100644 --- a/src/cypherpunks.ru/govpn/egd.go +++ b/src/cypherpunks.ru/govpn/egd.go @@ -1,6 +1,6 @@ /* GoVPN -- simple secure free software virtual private network daemon -Copyright (C) 2014-2017 Sergey Matveev +Copyright (C) 2014-2016 Sergey Matveev 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 @@ -22,6 +22,9 @@ import ( "crypto/rand" "io" "net" + + "github.com/Sirupsen/logrus" + "github.com/pkg/errors" ) // Rand is a source of entropy @@ -34,11 +37,17 @@ type EGDRand string func (egdPath EGDRand) Read(b []byte) (int, error) { conn, err := net.Dial("unix", string(egdPath)) if err != nil { - return 0, err + return 0, errors.Wrapf(err, "net.Dial unix:%q", string(egdPath)) + } + defer CloseLog(conn, logger, logrus.Fields{"func": logFuncPrefix + "EGDRand.Read"}) + n, err := conn.Write([]byte{0x02, byte(len(b))}) + if err != nil { + return 0, errors.Wrapf(err, "conn.Write unix:%q", string(egdPath)) + } + if n, err = io.ReadFull(conn, b); err != nil { + return 0, errors.Wrapf(err, wrapIoReadFull, string(egdPath)) } - defer conn.Close() - conn.Write([]byte{0x02, byte(len(b))}) - return io.ReadFull(conn, b) + return n, nil } // EGDInit sets random source to a EGD socket