Files: dcfed9ddf8af0a5b207553e837368fd98332a09b / mgsbot.go
1000 bytesRaw
1 | package main |
2 | |
3 | import ( |
4 | "context" |
5 | "os" |
6 | "os/signal" |
7 | "syscall" |
8 | "time" |
9 | |
10 | "go.cryptoscope.co/ssb/sbot" |
11 | ) |
12 | |
13 | func main() { |
14 | sbotOpts := []sbot.Option{ |
15 | sbot.DisableEBT(true), |
16 | sbot.DisableLegacyLiveReplication(false), |
17 | sbot.EnableAdvertismentBroadcasts(true), |
18 | sbot.EnableAdvertismentDialing(true), |
19 | sbot.LateOption(sbot.WithUNIXSocket()), |
20 | sbot.WithHops(3), |
21 | sbot.WithListenAddr(":8009"), |
22 | sbot.WithWebsocketAddress(":8988"), |
23 | } |
24 | |
25 | pub, err := sbot.New(sbotOpts...) |
26 | if err != nil { |
27 | panic(err) |
28 | } |
29 | |
30 | c := make(chan os.Signal) |
31 | signal.Notify(c, os.Interrupt, syscall.SIGTERM) |
32 | go func() { |
33 | <-c |
34 | |
35 | pub.Shutdown() |
36 | time.Sleep(2 * time.Second) |
37 | |
38 | err := pub.Close() |
39 | if err != nil { |
40 | panic(err) |
41 | } |
42 | |
43 | time.Sleep(2 * time.Second) |
44 | os.Exit(0) |
45 | }() |
46 | |
47 | for { |
48 | ctx := context.TODO() |
49 | |
50 | err = pub.Network.Serve(ctx) |
51 | if err != nil { |
52 | panic(err) |
53 | } |
54 | |
55 | time.Sleep(1 * time.Second) |
56 | |
57 | select { |
58 | case <-ctx.Done(): |
59 | err := pub.Close() |
60 | if err != nil { |
61 | panic(err) |
62 | } |
63 | default: |
64 | } |
65 | } |
66 | } |
67 |
Built with git-ssb-web