-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
57e8760
commit 997c62c
Showing
12 changed files
with
1,236 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
. "org.jboss.pnc.domain-proxy/pkg/client" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
domainProxyClient := NewDomainProxyClient() | ||
ready := make(chan bool) | ||
domainProxyClient.Start(ready) | ||
<-ready | ||
signals := make(chan os.Signal, 1) | ||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) | ||
<-signals | ||
domainProxyClient.Stop() | ||
} |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
. "org.jboss.pnc.domain-proxy/pkg/server" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
domainProxyServer := NewDomainProxyServer() | ||
ready := make(chan bool) | ||
domainProxyServer.Start(ready) | ||
<-ready | ||
signals := make(chan os.Signal, 1) | ||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) | ||
<-signals | ||
domainProxyServer.Stop() | ||
} |
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,15 @@ | ||
FROM registry.access.redhat.com/ubi9/go-toolset:1.22.5-1731639025@sha256:45170b6e45114849b5d2c0e55d730ffa4a709ddf5f58b9e810548097b085e78f as builder | ||
USER 0 | ||
WORKDIR /work | ||
COPY ./ . | ||
|
||
RUN go mod tidy | ||
RUN go build -o domainproxyserver cmd/server/main.go | ||
RUN go build -o domainproxyclient cmd/client/main.go | ||
|
||
FROM quay.io/konflux-ci/buildah-task:latest@sha256:5cbd487022fb7ac476cbfdea25513b810f7e343ec48f89dc6a4e8c3c39fa37a2 | ||
USER 0 | ||
WORKDIR /work/ | ||
|
||
COPY --from=builder /work/domainproxyserver /app/domain-proxy-server | ||
COPY --from=builder /work/domainproxyclient /app/domain-proxy-client |
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,10 @@ | ||
module org.jboss.pnc.domain-proxy | ||
|
||
go 1.23.4 | ||
|
||
require github.com/elazarl/goproxy v0.0.0-20241218172127-ac55c7698e0d | ||
|
||
require ( | ||
golang.org/x/net v0.32.0 // indirect | ||
golang.org/x/text v0.21.0 // indirect | ||
) |
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,8 @@ | ||
github.com/elazarl/goproxy v0.0.0-20241218172127-ac55c7698e0d h1:r8DboPPvhhSMCWfmBEDoLuNvHetXH8/AZUdaRLNYgXE= | ||
github.com/elazarl/goproxy v0.0.0-20241218172127-ac55c7698e0d/go.mod h1:3TKt+OFpElWuCtt5bphUyO97JT606j9Ffx4S2pfIcCo= | ||
github.com/elazarl/goproxy/ext v0.0.0-20241217120900-7711dfa3811c h1:R+i10jtNSzKJKqEZAYJnR9M8y14k0zrNHqD1xkv/A2M= | ||
github.com/elazarl/goproxy/ext v0.0.0-20241217120900-7711dfa3811c/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= | ||
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= | ||
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= | ||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= | ||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= |
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,110 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
. "org.jboss.pnc.domain-proxy/pkg/common" | ||
"time" | ||
) | ||
|
||
const ( | ||
Localhost = "localhost" | ||
HttpPortKey = "DOMAIN_PROXY_HTTP_PORT" | ||
DefaultHttpPort = 8080 | ||
HttpToDomainSocket = "HTTP <-> Domain Socket" | ||
) | ||
|
||
var logger = NewLogger("Domain Proxy Client") | ||
var common = NewCommon(logger) | ||
|
||
type DomainProxyClient struct { | ||
sharedParams *SharedParams | ||
httpPort int | ||
} | ||
|
||
func NewDomainProxyClient() *DomainProxyClient { | ||
return &DomainProxyClient{ | ||
sharedParams: common.NewSharedParams(), | ||
httpPort: getHttpPort(), | ||
} | ||
} | ||
|
||
func (dpc *DomainProxyClient) Start(ready chan<- bool) { | ||
sharedParams := dpc.sharedParams | ||
logger.Println("Starting domain proxy client...") | ||
var err error | ||
sharedParams.Listener, err = net.Listen(TCP, fmt.Sprintf("%s:%d", Localhost, dpc.httpPort)) | ||
if err != nil { | ||
logger.Fatalf("Failed to start HTTP server: %v", err) | ||
} | ||
go dpc.startClient(ready) | ||
} | ||
|
||
func (dpc *DomainProxyClient) startClient(ready chan<- bool) { | ||
sharedParams := dpc.sharedParams | ||
logger.Printf("HTTP server listening on port %d", dpc.httpPort) | ||
ready <- true | ||
for { | ||
select { | ||
case <-sharedParams.RunningContext.Done(): | ||
return | ||
default: | ||
if serverConnection, err := sharedParams.Listener.Accept(); err != nil { | ||
select { | ||
case <-sharedParams.RunningContext.Done(): | ||
return | ||
default: | ||
logger.Printf("Failed to accept server connection: %v", err) | ||
} | ||
} else { | ||
go dpc.handleConnectionRequest(serverConnection) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (dpc *DomainProxyClient) handleConnectionRequest(serverConnection net.Conn) { | ||
sharedParams := dpc.sharedParams | ||
if err := serverConnection.SetDeadline(time.Now().Add(sharedParams.IdleTimeout)); err != nil { | ||
common.HandleSetDeadlineError(serverConnection, err) | ||
return | ||
} | ||
connectionNo := sharedParams.HttpConnectionCounter.Add(1) | ||
logger.Printf("Handling %s Connection %d", HttpToDomainSocket, connectionNo) | ||
startTime := time.Now() | ||
domainConnection, err := net.DialTimeout(UNIX, sharedParams.DomainSocket, sharedParams.ConnectionTimeout) | ||
if err != nil { | ||
logger.Printf("Failed to connect to domain socket: %v", err) | ||
if err = serverConnection.Close(); err != nil { | ||
common.HandleConnectionCloseError(err) | ||
} | ||
return | ||
} | ||
if err := domainConnection.SetDeadline(time.Now().Add(sharedParams.IdleTimeout)); err != nil { | ||
common.HandleSetDeadlineError(domainConnection, err) | ||
if err = serverConnection.Close(); err != nil { | ||
common.HandleConnectionCloseError(err) | ||
} | ||
return | ||
} | ||
// Initiate transfer between server and domain | ||
go func() { | ||
common.BiDirectionalTransfer(sharedParams.RunningContext, serverConnection, domainConnection, sharedParams.ByteBufferSize, HttpToDomainSocket, connectionNo) | ||
logger.Printf("%s Connection %d ended after %d ms", HttpToDomainSocket, connectionNo, time.Since(startTime).Milliseconds()) | ||
}() | ||
} | ||
|
||
func (dpc *DomainProxyClient) Stop() { | ||
sharedParams := dpc.sharedParams | ||
logger.Println("Shutting down domain proxy client...") | ||
sharedParams.InitiateShutdown() | ||
if sharedParams.Listener != nil { | ||
if err := sharedParams.Listener.Close(); err != nil { | ||
common.HandleListenerCloseError(err) | ||
} | ||
} | ||
} | ||
|
||
func getHttpPort() int { | ||
return common.GetIntEnvVariable(HttpPortKey, DefaultHttpPort) | ||
} |
Oops, something went wrong.