mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Fixed settings and small typo.
This commit is contained in:
@@ -29,7 +29,7 @@ func Run() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("Listening for HTTP traffic on", Settings.address, ':', Settings.port, "port")
|
||||
fmt.Println("Listening for HTTP traffic on", Settings.Address())
|
||||
fmt.Println("Forwarding requests to replay server:", Settings.ReplayServer())
|
||||
|
||||
// Connection to reaplay server
|
||||
|
||||
@@ -49,7 +49,7 @@ func (t *RAWTCPListener) listen() {
|
||||
|
||||
select {
|
||||
case messages <- message:
|
||||
delete(t.messages, message.ask)
|
||||
delete(t.messages, message.ack)
|
||||
case packet := <-t.c_packets:
|
||||
t.processTCPPacket(packet)
|
||||
|
||||
@@ -103,18 +103,13 @@ func (t *RAWTCPListener) readTCPPackets() {
|
||||
|
||||
//
|
||||
func (t *RAWTCPListener) processTCPPacket(packet *TCPPacket) {
|
||||
// We interested only in packets that contain some data
|
||||
if !(packet.f_ask && packet.f_psh) {
|
||||
return
|
||||
ack := packet.acknowledgement
|
||||
|
||||
if _, ok := t.messages[ack]; !ok {
|
||||
t.messages[ack] = NewTCPMessage(ack)
|
||||
}
|
||||
|
||||
ask := packet.asknowledgement
|
||||
|
||||
if _, ok := t.messages[ask]; !ok {
|
||||
t.messages[ask] = NewTCPMessage(ask)
|
||||
}
|
||||
|
||||
t.messages[ask].AddPacket(packet)
|
||||
t.messages[ack].AddPacket(packet)
|
||||
}
|
||||
|
||||
func (t *RAWTCPListener) Receive() *TCPMessage {
|
||||
|
||||
@@ -34,7 +34,7 @@ func (s *ListenerSettings) ReplayServer() string {
|
||||
}
|
||||
|
||||
func (s *ListenerSettings) Address() string {
|
||||
return s.address + ':' + strconv.Itoa(s.port)
|
||||
return s.address + ":" + strconv.Itoa(s.port)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -8,20 +8,20 @@ import (
|
||||
// TCPMessage ensure that all TCP packets for given request is received, and processed in right sequence
|
||||
// Its needed because all TCP message can be fragmented or re-transmitted
|
||||
//
|
||||
// Each TCP Packet have 2 ids: asknowledgement - message_id, and sequence - packet_id
|
||||
// Each TCP Packet have 2 ids: acknowledgement - message_id, and sequence - packet_id
|
||||
// Message can be compiled from unique packets with same message_id which sorted by sequence
|
||||
// Message is received if we did't receive any packets for 200ms OR if we received packet with "fin" flag
|
||||
type TCPMessage struct {
|
||||
ask uint32 // Message ID
|
||||
ack uint32 // Message ID
|
||||
packets map[int]*TCPPacket // map[packet.sequence]*TCPPacket
|
||||
updated int64 // time of last packet
|
||||
}
|
||||
|
||||
func NewTCPMessage(ask uint32) (msg *TCPMessage) {
|
||||
func NewTCPMessage(ack uint32) (msg *TCPMessage) {
|
||||
msg = &TCPMessage{}
|
||||
msg.packets = make(map[int]*TCPPacket)
|
||||
msg.updated = time.Now().UnixNano()
|
||||
msg.ask = ask
|
||||
msg.ack = ack
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ type TCPPacket struct {
|
||||
dest_port uint16
|
||||
|
||||
sequence uint32
|
||||
asknowledgement uint32
|
||||
acknowledgement uint32
|
||||
|
||||
doff_reserved uint16
|
||||
tcph_length uint16
|
||||
@@ -28,7 +28,7 @@ type TCPPacket struct {
|
||||
f_crw bool
|
||||
f_ece bool
|
||||
f_urg bool
|
||||
f_ask bool
|
||||
f_ack bool
|
||||
f_psh bool
|
||||
f_rst bool
|
||||
f_syn bool
|
||||
@@ -59,7 +59,7 @@ func (t *TCPPacket) Parse() {
|
||||
t.read(&t.dest_port)
|
||||
|
||||
t.read(&t.sequence)
|
||||
t.read(&t.asknowledgement)
|
||||
t.read(&t.acknowledgement)
|
||||
t.read(&t.doff_reserved)
|
||||
|
||||
t.tcph_length = t.doff_reserved >> 12 * 4
|
||||
@@ -68,7 +68,7 @@ func (t *TCPPacket) Parse() {
|
||||
t.f_crw = (t.doff_reserved & 128) != 0
|
||||
t.f_ece = (t.doff_reserved & 64) != 0
|
||||
t.f_urg = (t.doff_reserved & 32) != 0
|
||||
t.f_ask = (t.doff_reserved & 16) != 0
|
||||
t.f_ack = (t.doff_reserved & 16) != 0
|
||||
t.f_psh = (t.doff_reserved & 8) != 0
|
||||
t.f_rst = (t.doff_reserved & 4) != 0
|
||||
t.f_syn = (t.doff_reserved & 2) != 0
|
||||
@@ -85,14 +85,14 @@ func (t *TCPPacket) String() string {
|
||||
"Source port: " + strconv.Itoa(int(t.source_port)),
|
||||
"Dest port:" + strconv.Itoa(int(t.dest_port)),
|
||||
"Sequence:" + strconv.Itoa(int(t.sequence)),
|
||||
"Acknowledgement:" + strconv.Itoa(int(t.asknowledgement)),
|
||||
"Acknowledgement:" + strconv.Itoa(int(t.acknowledgement)),
|
||||
"Header len:" + strconv.Itoa(int(t.tcph_length)),
|
||||
|
||||
"Flag ns:" + strconv.FormatBool(t.f_ns),
|
||||
"Flag crw:" + strconv.FormatBool(t.f_crw),
|
||||
"Flag ece:" + strconv.FormatBool(t.f_ece),
|
||||
"Flag urg:" + strconv.FormatBool(t.f_urg),
|
||||
"Flag ask:" + strconv.FormatBool(t.f_ask),
|
||||
"Flag ack:" + strconv.FormatBool(t.f_ack),
|
||||
"Flag psh:" + strconv.FormatBool(t.f_psh),
|
||||
"Flag rst:" + strconv.FormatBool(t.f_rst),
|
||||
"Flag syn:" + strconv.FormatBool(t.f_syn),
|
||||
|
||||
Reference in New Issue
Block a user