mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Add a TCP proxy for debugging. v6.0.117 (#3958)
When debugging the RTMP protocol, we can capture packets using tcpdump and then replay the pcap file. For example: ```bash cd ~/git/srs/trunk/3rdparty/srs-bench/pcap tcpdump -i any -w t.pcap tcp port 1935 go run . -f ./t.pcap -s 127.0.0.1:1935 ``` However, sometimes due to poor network conditions between the server and the client, there may be many retransmitted packets. In such cases, setting up a transparent TCP proxy that listens on port 1935 and forwards to port 19350 can be a solution: ```bash ./objs/srs -c conf/origin.conf cd 3rdparty/srs-bench/tcpproxy/ && go run main.go tcpdump -i any -w t.pcap tcp port 19350 ``` This approach allows for the implementation of packet dumping, multipoint replication, or the provision of detailed timestamps and byte information at the proxy. It enables the collection of debugging information without the need to modify the server. --------- `TRANS_BY_GPT4` --------- Co-authored-by: john <hondaxiao@tencent.com>
This commit is contained in:
parent
26f4ab9923
commit
ce2ce1542f
4 changed files with 176 additions and 6 deletions
20
trunk/3rdparty/srs-bench/pcap/main.go
vendored
20
trunk/3rdparty/srs-bench/pcap/main.go
vendored
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
|
@ -62,9 +63,19 @@ func doMain(ctx context.Context) error {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
r, err := pcapgo.NewNgReader(f, pcapgo.DefaultNgReaderOptions)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "new reader")
|
||||
var source *gopacket.PacketSource
|
||||
if strings.HasSuffix(filename, ".pcap") {
|
||||
r, err := pcapgo.NewReader(f)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "new reader")
|
||||
}
|
||||
source = gopacket.NewPacketSource(r, r.LinkType())
|
||||
} else {
|
||||
r, err := pcapgo.NewNgReader(f, pcapgo.DefaultNgReaderOptions)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "new reader")
|
||||
}
|
||||
source = gopacket.NewPacketSource(r, r.LinkType())
|
||||
}
|
||||
|
||||
// TODO: FIXME: Should start a goroutine to consume bytes from conn.
|
||||
|
@ -76,7 +87,6 @@ func doMain(ctx context.Context) error {
|
|||
|
||||
var packetNumber uint64
|
||||
var previousTime *time.Time
|
||||
source := gopacket.NewPacketSource(r, r.LinkType())
|
||||
for packet := range source.Packets() {
|
||||
packetNumber++
|
||||
|
||||
|
@ -90,7 +100,7 @@ func doMain(ctx context.Context) error {
|
|||
if len(payload) == 0 {
|
||||
continue
|
||||
}
|
||||
if tcp.DstPort != 1935 {
|
||||
if tcp.DstPort != 1935 && tcp.DstPort != 19350 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue