-
-
Notifications
You must be signed in to change notification settings - Fork 200
Removes dead connections #258
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"net/rpc" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/cretz/bine/tor" | ||
torEd25519 "github.com/cretz/bine/torutil/ed25519" | ||
|
@@ -80,6 +81,23 @@ func Start() error { | |
log.Println("Onion service running:", service.ID+".onion") | ||
|
||
loadData() | ||
|
||
// Spawn timer to clean dead connections every 5 mins | ||
timer := time.NewTicker(5 * time.Minute) | ||
go func() { | ||
for { | ||
select { | ||
case <-timer.C: | ||
Comment on lines
+88
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just do |
||
for i, _ := range activeClients { | ||
ac := getClient(i) | ||
if err := ac.getHostname(); err != nil { | ||
activeClients = append(activeClients[:i], activeClients[i+1:]...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a notification that a client disconnected
|
||
} | ||
} | ||
} | ||
} | ||
}() | ||
|
||
for { | ||
conn, err := service.Accept() | ||
if err != nil { | ||
|
@@ -117,6 +135,13 @@ func accept(conn net.Conn) { | |
|
||
saveData() | ||
|
||
// Remove previous dead entry if it exists | ||
for i, c := range activeClients { | ||
if c.Hostname == ac.Hostname { | ||
activeClients = append(activeClients[:i], activeClients[i+1:]...) | ||
} | ||
} | ||
Comment on lines
+139
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might introduce a bug where for whatever reason 2 client instances run on the same machine, this should therefore also check if the old session still works and keep it in that case. |
||
|
||
activeClients = append(activeClients, ac) | ||
fmt.Println(green("[Server] [+] New Client: "), blue(ac.Data().Name)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think every 5 minutes might be overly conservative