Rate-limit Add/Delete port mappings

Fixes #10
This commit is contained in:
Serhat Şevki Dinçer
2017-12-21 00:23:09 +03:00
parent 1be4557baa
commit a625a89506
2 changed files with 7 additions and 0 deletions

View File

@@ -63,17 +63,23 @@ func (d *IGD) Forward(port uint16, desc string) error {
return err
}
time.Sleep(time.Millisecond)
err = d.client.AddPortMapping("", port, "TCP", port, ip, true, desc, 0)
if err != nil {
return err
}
time.Sleep(time.Millisecond)
return d.client.AddPortMapping("", port, "UDP", port, ip, true, desc, 0)
}
// Clear un-forwards a port, removing it from the router's port mapping table.
func (d *IGD) Clear(port uint16) error {
time.Sleep(time.Millisecond)
tcpErr := d.client.DeletePortMapping("", port, "TCP")
time.Sleep(time.Millisecond)
udpErr := d.client.DeletePortMapping("", port, "UDP")
// only return an error if both deletions failed
if tcpErr != nil && udpErr != nil {
return tcpErr

View File

@@ -71,6 +71,7 @@ func TestIGD(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Log("Loc:", loc)
// connect to router directly
d, err = Load(loc)