Skip to content

Commit

Permalink
feat(me): concurrency send
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Aug 17, 2024
1 parent 1ba17fc commit bbe2c60
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions gold/link/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/fumiama/WireGold/config"
"github.com/fumiama/WireGold/gold/head"
"github.com/fumiama/WireGold/gold/p2p"
"github.com/fumiama/WireGold/helper"
"github.com/fumiama/WireGold/lower"
)

Expand Down Expand Up @@ -245,9 +246,14 @@ func (m *Me) sendAllSameDst(packet []byte) (n int) {
logrus.Warnln("[me] drop packet to", dst.String()+":"+strconv.Itoa(int(m.DstPort())), ": nil nexthop")
return
}
_, err := lnk.WriteAndPut(head.NewPacket(head.ProtoData, m.SrcPort(), lnk.peerip, m.DstPort(), packet), false)
if err != nil {
logrus.Warnln("[me] write to peer", lnk.peerip, "err:", err)
}
pcp := helper.MakeBytes(len(packet))
copy(pcp, packet)
go func(packet []byte) {
defer helper.PutBytes(packet)
_, err := lnk.WriteAndPut(head.NewPacket(head.ProtoData, m.SrcPort(), lnk.peerip, m.DstPort(), packet), false)
if err != nil {
logrus.Warnln("[me] write to peer", lnk.peerip, "err:", err)
}
}(pcp)
return
}

0 comments on commit bbe2c60

Please sign in to comment.