mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 19:14:01 +03:00
FILE / ScuroNeko/mtg
wrappers/stream/stats_telegram.go
Исходный файл и его история в репозитории.
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package stream
|
|
|
|
import (
|
|
"net"
|
|
"sync"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/9seconds/mtg/conntypes"
|
|
"github.com/9seconds/mtg/stats"
|
|
)
|
|
|
|
type wrapperTelegramStats struct {
|
|
parent conntypes.StreamReadWriteCloser
|
|
dc conntypes.DC
|
|
once sync.Once
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) Write(p []byte) (int, error) {
|
|
return w.parent.Write(p)
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
|
|
return w.parent.WriteTimeout(p, timeout)
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) Read(p []byte) (int, error) {
|
|
return w.parent.Read(p)
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
|
|
return w.parent.ReadTimeout(p, timeout)
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) Conn() net.Conn {
|
|
return w.parent.Conn()
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) Logger() *zap.SugaredLogger {
|
|
return w.parent.Logger().Named("stats-telegram")
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) LocalAddr() *net.TCPAddr {
|
|
return w.parent.LocalAddr()
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) RemoteAddr() *net.TCPAddr {
|
|
return w.parent.RemoteAddr()
|
|
}
|
|
|
|
func (w *wrapperTelegramStats) Close() error {
|
|
var err error
|
|
|
|
w.once.Do(func() {
|
|
err = w.parent.Close()
|
|
stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr())
|
|
})
|
|
|
|
return err
|
|
}
|
|
|
|
func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
|
|
conn := &wrapperTelegramStats{
|
|
parent: parent,
|
|
dc: dc,
|
|
}
|
|
|
|
stats.Stats.TelegramConnected(dc, parent.RemoteAddr())
|
|
|
|
return conn
|
|
}
|