mirror of
https://github.com/pion/webrtc.git
synced 2025-10-06 07:37:10 +08:00
Upgrade golangci-lint, more linters
Introduces new linters, upgrade golangci-lint to version (v1.63.4)
This commit is contained in:
@@ -38,6 +38,7 @@ import (
|
||||
+--------------------+ +--------------------+
|
||||
*/
|
||||
|
||||
// nolint:cyclop
|
||||
func main() {
|
||||
var inboundBytes int32 // for offerPeerConnection
|
||||
var outboundBytes int32 // for offerPeerConnection
|
||||
@@ -50,24 +51,25 @@ func main() {
|
||||
panicIfError(err)
|
||||
|
||||
// Add a filter that monitors the traffic on the router
|
||||
wan.AddChunkFilter(func(c vnet.Chunk) bool {
|
||||
netType := c.SourceAddr().Network()
|
||||
wan.AddChunkFilter(func(chunk vnet.Chunk) bool {
|
||||
netType := chunk.SourceAddr().Network()
|
||||
if netType == "udp" {
|
||||
dstAddr := c.DestinationAddr().String()
|
||||
dstAddr := chunk.DestinationAddr().String()
|
||||
host, _, err2 := net.SplitHostPort(dstAddr)
|
||||
panicIfError(err2)
|
||||
if host == "1.2.3.4" {
|
||||
// c.UserData() returns a []byte of UDP payload
|
||||
atomic.AddInt32(&inboundBytes, int32(len(c.UserData())))
|
||||
atomic.AddInt32(&inboundBytes, int32(len(chunk.UserData()))) //nolint:gosec // G115
|
||||
}
|
||||
srcAddr := c.SourceAddr().String()
|
||||
srcAddr := chunk.SourceAddr().String()
|
||||
host, _, err2 = net.SplitHostPort(srcAddr)
|
||||
panicIfError(err2)
|
||||
if host == "1.2.3.4" {
|
||||
// c.UserData() returns a []byte of UDP payload
|
||||
atomic.AddInt32(&outboundBytes, int32(len(c.UserData())))
|
||||
atomic.AddInt32(&outboundBytes, int32(len(chunk.UserData()))) //nolint:gosec // G115
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -133,18 +135,19 @@ func main() {
|
||||
|
||||
// Set the handler for Peer connection state
|
||||
// This will notify you when the peer has connected/disconnected
|
||||
offerPeerConnection.OnConnectionStateChange(func(s webrtc.PeerConnectionState) {
|
||||
fmt.Printf("Peer Connection State has changed: %s (offerer)\n", s.String())
|
||||
offerPeerConnection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||
fmt.Printf("Peer Connection State has changed: %s (offerer)\n", state.String())
|
||||
|
||||
if s == webrtc.PeerConnectionStateFailed {
|
||||
// Wait until PeerConnection has had no network activity for 30 seconds or another failure. It may be reconnected using an ICE Restart.
|
||||
if state == webrtc.PeerConnectionStateFailed {
|
||||
// Wait until PeerConnection has had no network activity for 30 seconds or another failure.
|
||||
// It may be reconnected using an ICE Restart.
|
||||
// Use webrtc.PeerConnectionStateDisconnected if you are interested in detecting faster timeout.
|
||||
// Note that the PeerConnection may come back from PeerConnectionStateDisconnected.
|
||||
fmt.Println("Peer Connection has gone to failed exiting")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if s == webrtc.PeerConnectionStateClosed {
|
||||
if state == webrtc.PeerConnectionStateClosed {
|
||||
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
|
||||
fmt.Println("Peer Connection has gone to closed exiting")
|
||||
os.Exit(0)
|
||||
@@ -153,18 +156,19 @@ func main() {
|
||||
|
||||
// Set the handler for Peer connection state
|
||||
// This will notify you when the peer has connected/disconnected
|
||||
answerPeerConnection.OnConnectionStateChange(func(s webrtc.PeerConnectionState) {
|
||||
fmt.Printf("Peer Connection State has changed: %s (answerer)\n", s.String())
|
||||
answerPeerConnection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||
fmt.Printf("Peer Connection State has changed: %s (answerer)\n", state.String())
|
||||
|
||||
if s == webrtc.PeerConnectionStateFailed {
|
||||
// Wait until PeerConnection has had no network activity for 30 seconds or another failure. It may be reconnected using an ICE Restart.
|
||||
if state == webrtc.PeerConnectionStateFailed {
|
||||
// Wait until PeerConnection has had no network activity for 30 seconds or another failure.
|
||||
// It may be reconnected using an ICE Restart.
|
||||
// Use webrtc.PeerConnectionStateDisconnected if you are interested in detecting faster timeout.
|
||||
// Note that the PeerConnection may come back from PeerConnectionStateDisconnected.
|
||||
fmt.Println("Peer Connection has gone to failed exiting")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if s == webrtc.PeerConnectionStateClosed {
|
||||
if state == webrtc.PeerConnectionStateClosed {
|
||||
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
|
||||
fmt.Println("Peer Connection has gone to closed exiting")
|
||||
os.Exit(0)
|
||||
@@ -173,17 +177,17 @@ func main() {
|
||||
|
||||
// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
|
||||
// send it to the other peer
|
||||
answerPeerConnection.OnICECandidate(func(i *webrtc.ICECandidate) {
|
||||
if i != nil {
|
||||
panicIfError(offerPeerConnection.AddICECandidate(i.ToJSON()))
|
||||
answerPeerConnection.OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
||||
if candidate != nil {
|
||||
panicIfError(offerPeerConnection.AddICECandidate(candidate.ToJSON()))
|
||||
}
|
||||
})
|
||||
|
||||
// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
|
||||
// send it to the other peer
|
||||
offerPeerConnection.OnICECandidate(func(i *webrtc.ICECandidate) {
|
||||
if i != nil {
|
||||
panicIfError(answerPeerConnection.AddICECandidate(i.ToJSON()))
|
||||
offerPeerConnection.OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
||||
if candidate != nil {
|
||||
panicIfError(answerPeerConnection.AddICECandidate(candidate.ToJSON()))
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user