pion / ice

A Go implementation of ICE
https://pion.ly/
MIT License
454 stars 160 forks source link

STUN Requests are not filtered #727

Open rahulshinde11 opened 2 months ago

rahulshinde11 commented 2 months ago

Your environment.

What did you do?

Force pion/ice to use a specific network interface for ICE gathering by using

settingEngine.SetInterfaceFilter(func(iface string) bool {
        return iface == "eth0" // wlan1
})

What did you expect?

I expect not to see any IP related to the filtered list. But I see the public IPs of both adapters

Here is the full example

package main

import (
    "fmt"

    "github.com/pion/webrtc/v3"
)

func main() {

    config := webrtc.Configuration{
        ICEServers: []webrtc.ICEServer{
            {
                URLs: []string{"stun:stun.l.google.com:19302"},
            },
        },
    }
    settingEngine := webrtc.SettingEngine{}
    settingEngine.SetInterfaceFilter(func(iface string) bool {
        return iface == "eth0" // wlan1
    })
    mediaEngine := webrtc.MediaEngine{}
    mediaEngine.RegisterDefaultCodecs()
    api := webrtc.NewAPI(webrtc.WithSettingEngine(settingEngine), webrtc.WithMediaEngine(&mediaEngine))
    peerConnection, _ := api.NewPeerConnection(config)
    peerConnection.OnICEGatheringStateChange(func(webrtc.ICEGathererState) {
        fmt.Println("ICE Gathering State has changed", peerConnection.ICEGatheringState())
    })

    peerConnection.OnICECandidate(func(c *webrtc.ICECandidate) {
        if c == nil {
            return
        }
        fmt.Println("ICE", c.ToJSON())
    })
    gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
    offer, err := peerConnection.CreateOffer(nil)
    if err != nil {
        panic(err)
    } else if err = peerConnection.SetLocalDescription(offer); err != nil {
        panic(err)
    }
    <-gatherComplete
}