hnakra/cmd/router/srvhnakra/hnakra.go

45 lines
877 B
Go
Raw Normal View History

2023-05-25 16:08:56 -06:00
package srvhnakra
import "log"
import "fmt"
import "net"
import "crypto/tls"
import "hnakra/router"
2023-05-26 11:05:22 -06:00
import "hnakra/router/config"
2023-05-25 16:08:56 -06:00
type Server struct {
underlying net.Listener
Config config.Config
Router *router.Router
running bool
2023-05-25 16:08:56 -06:00
}
2023-05-31 16:08:29 -06:00
func (server *Server) Run () (err error) {
2023-05-25 16:08:56 -06:00
server.underlying, err = tls.Listen (
"tcp", fmt.Sprint(":", server.Config.RouterPort()),
config.TLSConfigFor(server.Config))
if err != nil { return err }
server.running = true
2023-05-25 16:08:56 -06:00
log.Println(".// router on", server.underlying.Addr())
for {
conn, err := server.underlying.Accept()
if err != nil {
if server.running {
return err
} else {
return nil
}
}
2023-05-25 16:08:56 -06:00
log.Println("-=E incoming connection from", conn.RemoteAddr())
server.Router.Accept(conn)
}
}
2023-05-31 16:08:29 -06:00
func (server *Server) Shutdown () error {
server.running = false
2023-05-25 16:08:56 -06:00
return server.underlying.Close()
}