2021-01-24 05:00:26 -08:00
|
|
|
package main
|
2021-01-07 07:36:20 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
2021-01-09 03:26:30 -08:00
|
|
|
"time"
|
2021-01-07 07:36:20 -08:00
|
|
|
)
|
|
|
|
|
2021-01-17 12:43:23 -08:00
|
|
|
// End disconnects (from) all Peers and stops the process
|
2021-01-07 07:36:20 -08:00
|
|
|
func End(crash, reconnect bool) {
|
|
|
|
log.Print("Ending")
|
2021-01-09 03:26:30 -08:00
|
|
|
|
2021-04-02 04:39:35 -07:00
|
|
|
var reason uint8 = AccessDeniedShutdown
|
2021-01-07 07:36:20 -08:00
|
|
|
if crash {
|
2021-04-02 04:39:35 -07:00
|
|
|
reason = AccessDeniedCrash
|
2021-01-07 07:36:20 -08:00
|
|
|
}
|
2021-03-29 09:57:30 -07:00
|
|
|
|
|
|
|
for _, clt := range Conns() {
|
2021-04-02 04:39:35 -07:00
|
|
|
clt.CloseWith(reason, "", reconnect)
|
2021-01-07 07:36:20 -08:00
|
|
|
}
|
2021-01-09 03:26:30 -08:00
|
|
|
|
2021-03-09 09:06:05 -08:00
|
|
|
rpcSrvMu.Lock()
|
|
|
|
for srv := range rpcSrvs {
|
|
|
|
srv.Close()
|
|
|
|
}
|
|
|
|
rpcSrvMu.Unlock()
|
|
|
|
|
2021-01-07 07:36:20 -08:00
|
|
|
time.Sleep(time.Second)
|
2021-01-09 03:26:30 -08:00
|
|
|
|
2021-03-06 11:33:25 -08:00
|
|
|
Announce(AnnounceDelete)
|
|
|
|
|
2021-01-07 07:36:20 -08:00
|
|
|
if crash {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2021-04-02 04:39:35 -07:00
|
|
|
os.Exit(0)
|
2021-01-07 07:36:20 -08:00
|
|
|
}
|