+type InetdConn struct {
+ r *os.File
+ w *os.File
+}
+
+func (ic *InetdConn) Read(p []byte) (n int, err error) {
+ return ic.r.Read(p)
+}
+
+func (ic *InetdConn) Write(p []byte) (n int, err error) {
+ return ic.w.Write(p)
+}
+
+func (ic *InetdConn) SetReadDeadline(t time.Time) error {
+ return ic.r.SetReadDeadline(t)
+}
+
+func (ic *InetdConn) SetWriteDeadline(t time.Time) error {
+ return ic.w.SetWriteDeadline(t)
+}
+
+func performSP(ctx *nncp.Ctx, conn nncp.ConnDeadlined, nice uint8) {
+ state := nncp.SPState{
+ Ctx: ctx,
+ Nice: nice,
+ }
+ if err := state.StartR(conn); err == nil {
+ ctx.LogI("call-start", nncp.SDS{"node": state.Node.Id}, "connected")
+ state.Wait()
+ ctx.LogI("call-finish", nncp.SDS{
+ "node": state.Node.Id,
+ "duration": strconv.FormatInt(int64(state.Duration.Seconds()), 10),
+ "rxbytes": strconv.FormatInt(state.RxBytes, 10),
+ "txbytes": strconv.FormatInt(state.TxBytes, 10),
+ "rxspeed": strconv.FormatInt(state.RxSpeed, 10),
+ "txspeed": strconv.FormatInt(state.TxSpeed, 10),
+ }, "")
+ } else {
+ nodeId := "unknown"
+ if state.Node != nil {
+ nodeId = state.Node.Id.String()
+ }
+ ctx.LogE("call-start", nncp.SDS{"node": nodeId, "err": err}, "")
+ }
+}
+