mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
feat(proxy): add sd_notify support
This commit is contained in:
parent
70974640ab
commit
fa5be44b69
4 changed files with 43 additions and 0 deletions
|
@ -822,6 +822,8 @@ func (sf *SnowflakeProxy) Start() error {
|
|||
}
|
||||
tokens = newTokens(sf.Capacity)
|
||||
|
||||
sdnotifyStatus("Checking NAT type...")
|
||||
|
||||
err = sf.checkNATType(config, sf.NATProbeURL)
|
||||
if err != nil {
|
||||
// non-fatal error. Log it and continue
|
||||
|
@ -830,6 +832,9 @@ func (sf *SnowflakeProxy) Start() error {
|
|||
}
|
||||
sf.EventDispatcher.OnNewSnowflakeEvent(event.EventOnCurrentNATTypeDetermined{CurNATType: getCurrentNATType()})
|
||||
|
||||
sdnotifyStatus(fmt.Sprintf("NAT type: %s", getCurrentNATType()))
|
||||
sdnotifyReady()
|
||||
|
||||
NatRetestTask := task.Periodic{
|
||||
Interval: sf.NATTypeMeasurementInterval,
|
||||
Execute: func() error {
|
||||
|
@ -846,6 +851,16 @@ func (sf *SnowflakeProxy) Start() error {
|
|||
defer NatRetestTask.Close()
|
||||
}
|
||||
|
||||
WatchdogTask := task.Periodic{
|
||||
Interval: 5 * time.Minute,
|
||||
Execute: func() error {
|
||||
sdnotifyWatchdog()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
WatchdogTask.Start()
|
||||
defer WatchdogTask.Close()
|
||||
|
||||
ticker := time.NewTicker(sf.PollInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
|
@ -864,6 +879,7 @@ func (sf *SnowflakeProxy) Start() error {
|
|||
|
||||
// Stop closes all existing connections and shuts down the Snowflake.
|
||||
func (sf *SnowflakeProxy) Stop() {
|
||||
sdnotifyStopping()
|
||||
close(sf.shutdown)
|
||||
}
|
||||
|
||||
|
|
23
proxy/lib/systemd.go
Normal file
23
proxy/lib/systemd.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package snowflake_proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdnotify "github.com/coreos/go-systemd/v22/daemon"
|
||||
)
|
||||
|
||||
func sdnotifyReady() {
|
||||
sdnotify.SdNotify(false, sdnotify.SdNotifyReady)
|
||||
}
|
||||
|
||||
func sdnotifyStopping() {
|
||||
sdnotify.SdNotify(false, sdnotify.SdNotifyStopping)
|
||||
}
|
||||
|
||||
func sdnotifyStatus(status string) {
|
||||
sdnotify.SdNotify(false, fmt.Sprintf("STATUS=%s", status))
|
||||
}
|
||||
|
||||
func sdnotifyWatchdog() {
|
||||
sdnotify.SdNotify(false, sdnotify.SdNotifyWatchdog)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue