/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2022 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
"time"
"github.com/dustin/go-humanize"
- "go.cypherpunks.ru/nncp/v7"
+ "go.cypherpunks.ru/nncp/v8"
"golang.org/x/net/netutil"
)
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,
warranty = flag.Bool("warranty", false, "Print warranty information")
autoToss = flag.Bool("autotoss", false, "Toss after call is finished")
- autoTossDoSeen = flag.Bool("autotoss-seen", false, "Create .seen files during tossing")
+ autoTossDoSeen = flag.Bool("autotoss-seen", false, "Create seen/ files during tossing")
autoTossNoFile = flag.Bool("autotoss-nofile", false, "Do not process \"file\" packets during tossing")
autoTossNoFreq = flag.Bool("autotoss-nofreq", false, "Do not process \"freq\" packets during tossing")
autoTossNoExec = flag.Bool("autotoss-noexec", false, "Do not process \"exec\" packets during tossing")
ctx.Umask()
if *ucspi {
- os.Stderr.Close() // #nosec G104
- conn := &UCSPIConn{os.Stdin, os.Stdout}
+ os.Stderr.Close()
+ 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
close(autoTossFinish)
<-autoTossBadCode
}
- conn.Close() // #nosec G104
+ conn.Close()
return
}
close(autoTossFinish)
<-autoTossBadCode
}
- conn.Close() // #nosec G104
+ conn.Close()
}(conn)
}
}