-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
255 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
{{template "views/partials/head" .}} | ||
|
||
<body class="bg-gray-900 text-gray-200"> | ||
<div class="flex flex-col min-h-screen"> | ||
|
||
{{template "views/partials/navbar" .}} | ||
<div class="container mx-auto px-4 flex-grow"> | ||
|
||
<div class="models mt-12"> | ||
<h2 class="text-center text-3xl font-semibold text-gray-100"> | ||
P2P</h2> | ||
|
||
|
||
|
||
<div class="text-center text-xs font-semibold text-gray-100"> | ||
{{ range .Nodes }} | ||
<button hx-post="/browse/search/models" class="text-blue-500" hx-target="#search-results" | ||
hx-vals='{"search": "{{.ID}}"}' | ||
hx-indicator=".htmx-indicator" >{{.ID}} ({{.IsOnline}})</button> | ||
{{ end }} | ||
</div> | ||
|
||
|
||
</div> | ||
</div> | ||
|
||
{{template "views/partials/footer" .}} | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package p2p | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
) | ||
|
||
type NodeData struct { | ||
Name string | ||
ID string | ||
TunnelAddress string | ||
LastSeen time.Time | ||
} | ||
|
||
func (d NodeData) IsOnline() bool { | ||
now := time.Now() | ||
// if the node was seen in the last 40 seconds, it's online | ||
return now.Sub(d.LastSeen) < 40*time.Second | ||
} | ||
|
||
var mu sync.Mutex | ||
var nodes = map[string]NodeData{} | ||
|
||
func GetAvailableNodes() []NodeData { | ||
Check failure on line 24 in core/p2p/node.go GitHub Actions / build-linux-arm
|
||
mu.Lock() | ||
defer mu.Unlock() | ||
var availableNodes = []NodeData{} | ||
for _, v := range nodes { | ||
availableNodes = append(availableNodes, v) | ||
} | ||
return availableNodes | ||
} | ||
|
||
func AddNode(node NodeData) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
nodes[node.ID] = node | ||
} |
Oops, something went wrong.