Example #1
0
func (s *upnpSvc) Serve() {
	extPort := 0
	foundIGD := true
	s.stop = make(chan struct{})

	for {
		igds := upnp.Discover(time.Duration(s.cfg.Options().UPnPTimeoutS) * time.Second)
		if len(igds) > 0 {
			foundIGD = true
			extPort = s.tryIGDs(igds, extPort)
		} else if foundIGD {
			// Only print a notice if we've previously found an IGD or this is
			// the first time around.
			foundIGD = false
			l.Infof("No UPnP device detected")
		}

		d := time.Duration(s.cfg.Options().UPnPRenewalM) * time.Minute
		if d == 0 {
			// We always want to do renewal so lets just pick a nice sane number.
			d = 30 * time.Minute
		}

		select {
		case <-s.stop:
			return
		case <-time.After(d):
		}
	}
}
Example #2
0
func initForward() {
	nat = upnp.Discover(5 * time.Second)[0]
	err := forward.Forward(nat, forward.Mapping{Ports: []int{port}, Protocols: []upnp.Protocol{upnp.TCP}, Description: "Cluster"})
	if err != nil {
		log.Printf("Port forwarding failed: %v", err)
		log.Println(`You may have to mainually port forward or choose different ports`)
	} else {
		log.Println("Port Forwading Success!")
	}
}