mirror of
https://github.com/fosrl/gerbil.git
synced 2026-02-26 23:06:41 +00:00
Move to post
This commit is contained in:
@@ -26,8 +26,7 @@ type RouteRecord struct {
|
|||||||
|
|
||||||
// RouteAPIResponse represents the response from the route API
|
// RouteAPIResponse represents the response from the route API
|
||||||
type RouteAPIResponse struct {
|
type RouteAPIResponse struct {
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoints []string `json:"endpoints"`
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SNIProxy represents the main proxy server
|
// SNIProxy represents the main proxy server
|
||||||
@@ -42,6 +41,7 @@ type SNIProxy struct {
|
|||||||
localProxyAddr string
|
localProxyAddr string
|
||||||
localProxyPort int
|
localProxyPort int
|
||||||
remoteConfigURL string
|
remoteConfigURL string
|
||||||
|
publicKey string
|
||||||
|
|
||||||
// New fields for fast local SNI lookup
|
// New fields for fast local SNI lookup
|
||||||
localSNIs map[string]struct{}
|
localSNIs map[string]struct{}
|
||||||
@@ -74,7 +74,7 @@ func (conn readOnlyConn) SetReadDeadline(t time.Time) error { return nil }
|
|||||||
func (conn readOnlyConn) SetWriteDeadline(t time.Time) error { return nil }
|
func (conn readOnlyConn) SetWriteDeadline(t time.Time) error { return nil }
|
||||||
|
|
||||||
// NewSNIProxy creates a new SNI proxy instance
|
// NewSNIProxy creates a new SNI proxy instance
|
||||||
func NewSNIProxy(port int, remoteConfigURL, exitNodeName, localProxyAddr string, localProxyPort int, localOverrides []string) (*SNIProxy, error) {
|
func NewSNIProxy(port int, remoteConfigURL, publicKey, exitNodeName, localProxyAddr string, localProxyPort int, localOverrides []string) (*SNIProxy, error) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
// Create local overrides map
|
// Create local overrides map
|
||||||
@@ -94,6 +94,7 @@ func NewSNIProxy(port int, remoteConfigURL, exitNodeName, localProxyAddr string,
|
|||||||
localProxyAddr: localProxyAddr,
|
localProxyAddr: localProxyAddr,
|
||||||
localProxyPort: localProxyPort,
|
localProxyPort: localProxyPort,
|
||||||
remoteConfigURL: remoteConfigURL,
|
remoteConfigURL: remoteConfigURL,
|
||||||
|
publicKey: publicKey,
|
||||||
localSNIs: make(map[string]struct{}),
|
localSNIs: make(map[string]struct{}),
|
||||||
localOverrides: overridesMap,
|
localOverrides: overridesMap,
|
||||||
activeTunnels: make(map[string]*activeTunnel),
|
activeTunnels: make(map[string]*activeTunnel),
|
||||||
@@ -337,14 +338,26 @@ func (p *SNIProxy) getRoute(hostname string) (*RouteRecord, error) {
|
|||||||
ctx, cancel := context.WithTimeout(p.ctx, 5*time.Second)
|
ctx, cancel := context.WithTimeout(p.ctx, 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Construct API URL
|
// Construct API URL (without hostname in path)
|
||||||
apiURL := fmt.Sprintf("%s/gerbil/get-resolved-hostname/%s", p.remoteConfigURL, hostname)
|
apiURL := fmt.Sprintf("%s/gerbil/get-resolved-hostname", p.remoteConfigURL)
|
||||||
|
|
||||||
|
// Create request body with hostname and public key
|
||||||
|
requestBody := map[string]string{
|
||||||
|
"hostname": hostname,
|
||||||
|
"publicKey": p.publicKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBody, err := json.Marshal(requestBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to marshal request body: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Create HTTP request
|
// Create HTTP request
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", apiURL, nil)
|
req, err := http.NewRequestWithContext(ctx, "POST", apiURL, bytes.NewBuffer(jsonBody))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||||
}
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
// Make HTTP request
|
// Make HTTP request
|
||||||
client := &http.Client{Timeout: 5 * time.Second}
|
client := &http.Client{Timeout: 5 * time.Second}
|
||||||
@@ -370,7 +383,7 @@ func (p *SNIProxy) getRoute(hostname string) (*RouteRecord, error) {
|
|||||||
return nil, fmt.Errorf("failed to decode API response: %w", err)
|
return nil, fmt.Errorf("failed to decode API response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := apiResponse.Endpoint
|
endpoints := apiResponse.Endpoints
|
||||||
name := apiResponse.Name
|
name := apiResponse.Name
|
||||||
|
|
||||||
// If the endpoint matches the current exit node, use the local proxy address
|
// If the endpoint matches the current exit node, use the local proxy address
|
||||||
@@ -379,7 +392,7 @@ func (p *SNIProxy) getRoute(hostname string) (*RouteRecord, error) {
|
|||||||
if name == p.exitNodeName {
|
if name == p.exitNodeName {
|
||||||
targetHost = p.localProxyAddr
|
targetHost = p.localProxyAddr
|
||||||
targetPort = p.localProxyPort
|
targetPort = p.localProxyPort
|
||||||
}
|
} // THIS IS SAYING TO ROUTE IT LOCALLY IF IT MATCHES - idk HOW TO KEEP THIS
|
||||||
|
|
||||||
route := &RouteRecord{
|
route := &RouteRecord{
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
|
|||||||
Reference in New Issue
Block a user