refactor: separate core components and improve session & server handling

This commit is contained in:
2025-02-06 22:14:13 +07:00
parent dc219e2f7f
commit 8a1604fde8
9 changed files with 556 additions and 287 deletions

42
server/server.go Normal file
View File

@ -0,0 +1,42 @@
package server
import (
"fmt"
"golang.org/x/crypto/ssh"
"log"
"net"
"net/http"
httpServer "tunnel_pls/http"
)
type Server struct {
Conn *net.Listener
Config *ssh.ServerConfig
HttpServer *http.Server
}
func NewServer(config ssh.ServerConfig) *Server {
listener, err := net.Listen("tcp", ":2200")
if err != nil {
log.Fatalf("failed to listen on port 2200: %v", err)
return nil
}
go httpServer.Listen()
return &Server{
Conn: &listener,
Config: &config,
}
}
func (s *Server) Start() {
fmt.Println("SSH server is starting on port 2200...")
for {
conn, err := (*s.Conn).Accept()
if err != nil {
log.Printf("failed to accept connection: %v", err)
continue
}
go s.handleConnection(conn)
}
}