mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Remove unused fields from packet
This commit is contained in:
@@ -36,7 +36,7 @@ type Listener struct {
|
||||
mu sync.Mutex
|
||||
// buffer of TCPMessages waiting to be send
|
||||
// ID -> TCPMessage
|
||||
messages map[[10]byte]*TCPMessage
|
||||
messages map[tcpID]*TCPMessage
|
||||
|
||||
// Expect: 100-continue request is send in 2 tcp messages
|
||||
// We store ACK aliases to merge this packets together
|
||||
@@ -48,7 +48,7 @@ type Listener struct {
|
||||
respAliases map[uint32]*request
|
||||
|
||||
// Ack -> ID
|
||||
respWithoutReq map[uint32][10]byte
|
||||
respWithoutReq map[uint32]tcpID
|
||||
|
||||
// Messages ready to be send to client
|
||||
packetsChan chan []byte
|
||||
@@ -67,7 +67,7 @@ type Listener struct {
|
||||
}
|
||||
|
||||
type request struct {
|
||||
id [10]byte
|
||||
id tcpID
|
||||
start time.Time
|
||||
ack uint32
|
||||
}
|
||||
@@ -87,11 +87,11 @@ func NewListener(addr string, port string, engine int, expire time.Duration) (l
|
||||
l.quit = make(chan bool)
|
||||
l.readyCh = make(chan bool, 1)
|
||||
|
||||
l.messages = make(map[[10]byte]*TCPMessage)
|
||||
l.messages = make(map[tcpID]*TCPMessage)
|
||||
l.ackAliases = make(map[uint32]uint32)
|
||||
l.seqWithData = make(map[uint32]uint32)
|
||||
l.respAliases = make(map[uint32]*request)
|
||||
l.respWithoutReq = make(map[uint32][10]byte)
|
||||
l.respWithoutReq = make(map[uint32]tcpID)
|
||||
|
||||
l.addr = addr
|
||||
_port, _ := strconv.Atoi(port)
|
||||
|
||||
@@ -23,7 +23,7 @@ type TCPMessage struct {
|
||||
ResponseAck uint32
|
||||
RequestStart time.Time
|
||||
RequestAck uint32
|
||||
RequestID [10]byte
|
||||
RequestID tcpID
|
||||
Start time.Time
|
||||
End time.Time
|
||||
IsIncoming bool
|
||||
@@ -196,13 +196,13 @@ func (t *TCPMessage) UpdateResponseAck() uint32 {
|
||||
return t.ResponseAck
|
||||
}
|
||||
|
||||
func (t *TCPMessage) ID() [10]byte {
|
||||
func (t *TCPMessage) ID() tcpID {
|
||||
return t.packets[0].ID
|
||||
}
|
||||
|
||||
// ResponseID generate message ID for request response
|
||||
func (t *TCPMessage) ResponseID() [10]byte {
|
||||
var id [10]byte
|
||||
func (t *TCPMessage) ResponseID() tcpID {
|
||||
var id tcpID
|
||||
p := t.packets[0]
|
||||
|
||||
copy(id[:4], p.Addr)
|
||||
|
||||
@@ -19,6 +19,8 @@ const (
|
||||
fNS
|
||||
)
|
||||
|
||||
type tcpID [10]byte
|
||||
|
||||
// TCPPacket provides tcp packet parser
|
||||
// Packet structure: http://en.wikipedia.org/wiki/Transmission_Control_Protocol
|
||||
type TCPPacket struct {
|
||||
@@ -27,15 +29,11 @@ type TCPPacket struct {
|
||||
Seq uint32
|
||||
Ack uint32
|
||||
DataOffset uint8
|
||||
Flags uint16
|
||||
Window uint16
|
||||
Checksum uint16
|
||||
Urgent uint16
|
||||
|
||||
Raw []byte
|
||||
Data []byte
|
||||
Addr []byte
|
||||
ID [10]byte
|
||||
ID tcpID
|
||||
}
|
||||
|
||||
// ParseTCPPacket takes address and tcp payload and returns parsed TCPPacket
|
||||
@@ -92,19 +90,6 @@ func (t *TCPPacket) String() string {
|
||||
"Acknowledgment:" + strconv.Itoa(int(t.Ack)),
|
||||
"Header len:" + strconv.Itoa(int(t.DataOffset)),
|
||||
|
||||
"Flag ns:" + strconv.FormatBool(t.Flags&fNS != 0),
|
||||
"Flag crw:" + strconv.FormatBool(t.Flags&fCWR != 0),
|
||||
"Flag ece:" + strconv.FormatBool(t.Flags&fECE != 0),
|
||||
"Flag urg:" + strconv.FormatBool(t.Flags&fURG != 0),
|
||||
"Flag ack:" + strconv.FormatBool(t.Flags&fACK != 0),
|
||||
"Flag psh:" + strconv.FormatBool(t.Flags&fPSH != 0),
|
||||
"Flag rst:" + strconv.FormatBool(t.Flags&fRST != 0),
|
||||
"Flag syn:" + strconv.FormatBool(t.Flags&fSYN != 0),
|
||||
"Flag fin:" + strconv.FormatBool(t.Flags&fFIN != 0),
|
||||
|
||||
"Window size:" + strconv.Itoa(int(t.Window)),
|
||||
"Checksum:" + strconv.Itoa(int(t.Checksum)),
|
||||
|
||||
"Data size:" + strconv.Itoa(len(t.Data)),
|
||||
"Data:" + string(t.Data[:maxLen]),
|
||||
}, "\n")
|
||||
|
||||
Reference in New Issue
Block a user