mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-05 13:08:57 +07:00
c3ccf179d9
Co-authored-by: dae-prow[bot] <136105375+dae-prow[bot]@users.noreply.github.com> Co-authored-by: Sumire (菫) <151038614+sumire88@users.noreply.github.com>
45 lines
795 B
Go
45 lines
795 B
Go
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* Copyright (c) 2022-2024, daeuniverse Organization <dae@v2raya.org>
|
|
*/
|
|
|
|
package sniffing
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type ConnSniffer struct {
|
|
net.Conn
|
|
*Sniffer
|
|
}
|
|
|
|
func NewConnSniffer(conn net.Conn, timeout time.Duration) *ConnSniffer {
|
|
s := &ConnSniffer{
|
|
Conn: conn,
|
|
Sniffer: NewStreamSniffer(conn, timeout),
|
|
}
|
|
return s
|
|
}
|
|
|
|
func (s *ConnSniffer) Read(p []byte) (n int, err error) {
|
|
return s.Sniffer.Read(p)
|
|
}
|
|
|
|
func (s *ConnSniffer) Close() (err error) {
|
|
var errs []string
|
|
if err = s.Sniffer.Close(); err != nil {
|
|
errs = append(errs, err.Error())
|
|
}
|
|
if err = s.Conn.Close(); err != nil {
|
|
errs = append(errs, err.Error())
|
|
}
|
|
if len(errs) > 0 {
|
|
return errors.New(strings.Join(errs, "; "))
|
|
}
|
|
return nil
|
|
}
|