+ if area == nil {
+ go func(src io.Reader, dst io.WriteCloser) {
+ ctx.LogD("tx", LEs{
+ {"Node", hops[0].Id},
+ {"Nice", int(nice)},
+ {"Size", expectedSize},
+ }, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tx packet to %s (source %s) nice: %s",
+ ctx.NodeName(hops[0].Id),
+ humanize.IBytes(uint64(expectedSize)),
+ NicenessFmt(nice),
+ )
+ })
+ pktEncRaw, size, err := PktEncWrite(
+ ctx.Self, hops[0], pkt, nice, minSize, maxSize, wrappers, src, dst,
+ )
+ results <- PktEncWriteResult{pktEncRaw, size, err}
+ dst.Close()
+ }(src, pipeW)
+ } else {
+ go func(src io.Reader, dst io.WriteCloser) {
+ ctx.LogD("tx", LEs{
+ {"Area", area.Id},
+ {"Nice", int(nice)},
+ {"Size", expectedSize},
+ }, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tx area packet to %s (source %s) nice: %s",
+ ctx.AreaName(areaId),
+ humanize.IBytes(uint64(expectedSize)),
+ NicenessFmt(nice),
+ )
+ })
+ areaNode := Node{Id: new(NodeId), ExchPub: new([32]byte)}
+ copy(areaNode.Id[:], area.Id[:])
+ copy(areaNode.ExchPub[:], area.Pub[:])
+ pktEncRaw, size, err := PktEncWrite(
+ ctx.Self, &areaNode, pkt, nice, 0, maxSize, 0, src, dst,
+ )
+ results <- PktEncWriteResult{pktEncRaw, size, err}
+ dst.Close()
+ }(src, pipeW)
+ pipeRPrev = pipeR
+ pipeR, pipeW = io.Pipe()
+ go func(src io.Reader, dst io.WriteCloser) {
+ pktArea, err := NewPkt(PktTypeArea, 0, area.Id[:])
+ if err != nil {
+ panic(err)
+ }
+ ctx.LogD("tx", LEs{
+ {"Node", hops[0].Id},
+ {"Nice", int(nice)},
+ {"Size", expectedSize},
+ }, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tx packet to %s (source %s) nice: %s",
+ ctx.NodeName(hops[0].Id),
+ humanize.IBytes(uint64(expectedSize)),
+ NicenessFmt(nice),
+ )
+ })
+ pktEncRaw, size, err := PktEncWrite(
+ ctx.Self, hops[0], pktArea, nice, minSize, maxSize, wrappers, src, dst,
+ )
+ results <- PktEncWriteResult{pktEncRaw, size, err}
+ dst.Close()
+ }(pipeRPrev, pipeW)
+ }