X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-daemon%2Fmain.go;fp=src%2Fcmd%2Fnncp-daemon%2Fmain.go;h=485199ceb629e93480409bef7ee11e0244c116ec;hb=bd98bc071da6b50d20ddf1df02af69111df4831c;hp=f27c2a371461b0dad558509be8a09f670c75b507;hpb=9481faded654975d4bc0539412fd925a278b51bd;p=nncp.git diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index f27c2a3..485199c 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp-daemon/main.go @@ -40,35 +40,6 @@ func usage() { flag.PrintDefaults() } -type UCSPIConn struct { - r *os.File - w *os.File -} - -func (c UCSPIConn) Read(p []byte) (n int, err error) { - return c.r.Read(p) -} - -func (c UCSPIConn) Write(p []byte) (n int, err error) { - return c.w.Write(p) -} - -func (c UCSPIConn) SetReadDeadline(t time.Time) error { - return c.r.SetReadDeadline(t) -} - -func (c UCSPIConn) SetWriteDeadline(t time.Time) error { - return c.w.SetWriteDeadline(t) -} - -func (c UCSPIConn) Close() error { - if err := c.r.Close(); err != nil { - c.w.Close() // #nosec G104 - return err - } - return c.w.Close() -} - func performSP( ctx *nncp.Ctx, conn nncp.ConnDeadlined, @@ -198,16 +169,11 @@ func main() { if *ucspi { os.Stderr.Close() // #nosec G104 - conn := &UCSPIConn{os.Stdin, os.Stdout} + conn := &nncp.UCSPIConn{R: os.Stdin, W: os.Stdout} nodeIdC := make(chan *nncp.NodeId) - addr := "PIPE" - if proto := os.Getenv("PROTO"); proto == "TCP" { - port := os.Getenv("TCPREMOTEPORT") - if host := os.Getenv("TCPREMOTEHOST"); host == "" { - addr = fmt.Sprintf("[%s]:%s", os.Getenv("TCPREMOTEIP"), port) - } else { - addr = fmt.Sprintf("%s:%s", host, port) - } + addr := nncp.UCSPITCPRemoteAddr() + if addr == "" { + addr = "PIPE" } go performSP(ctx, conn, addr, nice, *noCK, nodeIdC) nodeId := <-nodeIdC