@@ -145,6 +145,10 @@ func (sd *Dispatcher) Enable() bool {
145
145
}
146
146
147
147
func (sd * Dispatcher ) sniffDomain (conn * N.BufferedConn , metadata * C.Metadata ) (string , error ) {
148
+ //defer func(start time.Time) {
149
+ // log.Debugln("[Sniffer] [%s] Sniffing took %s", metadata.DstIP, time.Since(start))
150
+ //}(time.Now())
151
+
148
152
for s := range sd .sniffers {
149
153
if s .SupportNetwork () == C .TCP && s .SupportPort (metadata .DstPort ) {
150
154
_ = conn .SetReadDeadline (time .Now ().Add (1 * time .Second ))
@@ -154,7 +158,7 @@ func (sd *Dispatcher) sniffDomain(conn *N.BufferedConn, metadata *C.Metadata) (s
154
158
_ , ok := err .(* net.OpError )
155
159
if ok {
156
160
sd .cacheSniffFailed (metadata )
157
- log .Errorln ("[Sniffer] [%s] may not have any sent data, Consider adding skip" , metadata .DstIP . String ())
161
+ log .Errorln ("[Sniffer] [%s] [%s] may not have any sent data, Consider adding skip" , metadata .DstIP , s . Protocol ())
158
162
_ = conn .Close ()
159
163
}
160
164
@@ -164,22 +168,36 @@ func (sd *Dispatcher) sniffDomain(conn *N.BufferedConn, metadata *C.Metadata) (s
164
168
bufferedLen := conn .Buffered ()
165
169
bytes , err := conn .Peek (bufferedLen )
166
170
if err != nil {
167
- log .Debugln ("[Sniffer] the data length not enough" )
171
+ log .Debugln ("[Sniffer] [%s] [%s] the data length not enough, error: %v" , metadata . DstIP , s . Protocol (), err )
168
172
continue
169
173
}
170
174
171
175
host , err := s .SniffData (bytes )
176
+ var e * errNeedAtLeastData
177
+ if errors .As (err , & e ) {
178
+ //log.Debugln("[Sniffer] [%s] [%s] %v, got length: %d", metadata.DstIP, s.Protocol(), e, len(bytes))
179
+ _ = conn .SetReadDeadline (time .Now ().Add (1 * time .Second ))
180
+ bytes , err = conn .Peek (e .length )
181
+ _ = conn .SetReadDeadline (time.Time {})
182
+ //log.Debugln("[Sniffer] [%s] [%s] try again, got length: %d", metadata.DstIP, s.Protocol(), len(bytes))
183
+ if err != nil {
184
+ log .Debugln ("[Sniffer] [%s] [%s] the data length not enough, error: %v" , metadata .DstIP , s .Protocol (), err )
185
+ continue
186
+ }
187
+ host , err = s .SniffData (bytes )
188
+ }
172
189
if err != nil {
173
- //log.Debugln("[Sniffer] [%s] Sniff data failed %s ", s.Protocol(), metadata.DstIP )
190
+ //log.Debugln("[Sniffer] [%s] [%s] Sniff data failed, error: %v ", metadata.DstIP, s.Protocol(), err )
174
191
continue
175
192
}
176
193
177
194
_ , err = netip .ParseAddr (host )
178
195
if err == nil {
179
- //log.Debugln("[Sniffer] [%s] Sniff data failed %s ", s.Protocol(), metadata.DstIP )
196
+ //log.Debugln("[Sniffer] [%s] [%s] Sniff data failed, got host [%s] ", metadata.DstIP, s.Protocol(), host )
180
197
continue
181
198
}
182
199
200
+ //log.Debugln("[Sniffer] [%s] [%s] Sniffed [%s]", metadata.DstIP, s.Protocol(), host)
183
201
return host , nil
184
202
}
185
203
}
0 commit comments