2 Commits

Author SHA1 Message Date
jdl
926e111c3f Cleanup 2026-06-12 18:22:25 +02:00
9a3cb2d1c2 Refactor - now wireguard based. (#7) 2026-06-12 15:11:01 +00:00
6 changed files with 14 additions and 19 deletions

View File

@@ -1,11 +1,5 @@
# vppn: Virtual Potentially Private Network
## TO DO
* peer - write status to file instead of using sockets
* peer - improve relay selection
* Double buffering in IFReader and ConnReader ?
## Hub Server Configuration
```
@@ -59,15 +53,17 @@ Sign-in and configure.
Install the binary somewhere, for example `~/bin/vppn`.
Add the API key for your network name in `~/.vppn/<netname>/apikey`.
Create systemd file in `/etc/systemd/system/vppn.service`.
```
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
AmbientCapabilities=AP_NET_ADMIN CAP_DAC_OVERRIDE CAP_CHOWN
Type=simple
User=user
WorkingDirectory=/home/user/
ExecStart=/home/user/vppn run my_net_name https://my.hub my_api_key
ExecStart=/home/user/bin/vppn -name my_net_name -hub https://my.hub
Restart=always
RestartSec=8
TimeoutStopSec=24

View File

@@ -11,9 +11,3 @@ func Peer_GetByAPIKey(tx TX, apiKey string) (*Peer, error) {
Peer_SelectQuery+` WHERE APIKey=?`,
apiKey)
}
func Peer_Exists(tx TX, networkID int64, ip byte) (exists bool, err error) {
const query = `SELECT EXISTS(SELECT 1 FROM peers WHERE NetworkID=? AND PeerIP=?)`
err = tx.QueryRow(query, networkID, ip).Scan(&exists)
return
}

View File

@@ -1,5 +1,5 @@
package hub
const (
SESSION_ID_COOKIE_NAME = "SessionID"
sessionIDCookieName = "SessionID"
)

View File

@@ -12,7 +12,7 @@ type handlerFunc func(s *api.Session, w http.ResponseWriter, r *http.Request) er
func (app *App) handlePub(pattern string, fn handlerFunc) {
wrapped := func(w http.ResponseWriter, r *http.Request) {
sessionID := app.getCookie(r, SESSION_ID_COOKIE_NAME)
sessionID := app.getCookie(r, sessionIDCookieName)
s, err := app.api.Session_Get(sessionID)
if err != nil {
log.Printf("Failed to get session: %v", err)

View File

@@ -38,7 +38,7 @@ func (a *App) _signinSubmit(s *api.Session, w http.ResponseWriter, r *http.Reque
if err != nil {
return err
}
a.setCookie(w, SESSION_ID_COOKIE_NAME, sess.SessionID)
a.setCookie(w, sessionIDCookieName, sess.SessionID)
return a.redirect(w, r, "/")
}
@@ -51,7 +51,7 @@ func (a *App) _adminSignOutSubmit(s *api.Session, w http.ResponseWriter, r *http
if err := a.api.Session_Delete(s.SessionID); err != nil {
log.Printf("Failed to delete session cookie %s: %v", s.SessionID, err)
}
a.deleteCookie(w, SESSION_ID_COOKIE_NAME)
a.deleteCookie(w, sessionIDCookieName)
return a.redirect(w, r, "/")
}

View File

@@ -57,7 +57,12 @@ func (a *App) devSetRelay(p *Peer, endpoint netip.AddrPort) {
}
func (a *App) devPromote(p *Peer) {
log.Printf("PROMOTED: %s - %s @ %s", p.Name, p.VPNIP.String(), p.WGEndpoint().String())
ep := p.WGEndpoint()
if ep.IsValid() {
log.Printf("PROMOTED: %s - %s @ %s", p.Name, p.VPNIP.String(), p.WGEndpoint().String())
} else {
log.Printf("PROMOTED: %s - %s (no IP)", p.Name, p.VPNIP.String())
}
devRetry(p.VPNIP, "Promote", func() error { return a.dev.Promote(p.PubKey(), p.VPNIP) })
p.State = StateDirect
}