-
Notifications
You must be signed in to change notification settings - Fork 624
https+tcp+sni listener support #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nathanejohnson
merged 1 commit into
fabiolb:master
from
nathanejohnson:feature/httpstcpsni
Sep 3, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,104 @@ | ||
| package proxy | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "log" | ||
| "net" | ||
| "net/http" | ||
|
|
||
| "github.com/inetaf/tcpproxy" | ||
| ) | ||
|
|
||
| type childProxy struct { | ||
| l net.Listener | ||
| s Server | ||
| } | ||
|
|
||
| type InetAfTCPProxyServer struct { | ||
| Proxy *tcpproxy.Proxy | ||
| children []*childProxy | ||
| } | ||
|
|
||
| // Close - implements Server - is this even called? | ||
| func (tps *InetAfTCPProxyServer) Close() error { | ||
| _ = tps.Proxy.Close() | ||
| firstErr := tps.Proxy.Wait() | ||
| errChan := make(chan error, len(tps.children)) | ||
| for _, sl := range tps.children { | ||
| go func(sl *childProxy) { | ||
| errChan <- sl.s.Close() | ||
| }(sl) | ||
| } | ||
| for range tps.children { | ||
| err := <-errChan | ||
| if errors.Is(err, http.ErrServerClosed) { | ||
| err = nil | ||
| } | ||
| if firstErr == nil { | ||
| firstErr = err | ||
| } | ||
| if err != nil { | ||
| log.Printf("[ERROR] %s", err) | ||
| } | ||
| } | ||
| return firstErr | ||
|
|
||
| } | ||
|
|
||
| // Serve - implements server. The listener is ignored, but it | ||
| // calls serve on the children | ||
| func (tps *InetAfTCPProxyServer) Serve(_ net.Listener) error { | ||
| if len(tps.children) == 0 { | ||
| return fmt.Errorf("no children defined for listener") | ||
| } | ||
| errChan := make(chan error, len(tps.children)) | ||
|
nathanejohnson marked this conversation as resolved.
Outdated
|
||
| for _, sl := range tps.children { | ||
| go func(sl *childProxy) { | ||
| errChan <- sl.s.Serve(sl.l) | ||
| }(sl) | ||
| } | ||
| firstErr := tps.Proxy.Wait() | ||
| for range tps.children { | ||
| err := <-errChan | ||
| if errors.Is(err, http.ErrServerClosed) { | ||
| err = nil | ||
| } | ||
| if firstErr == nil { | ||
| firstErr = err | ||
| } | ||
| if err != nil { | ||
| log.Print("[FATAL] ", err) | ||
| } | ||
| } | ||
| return firstErr | ||
| } | ||
|
|
||
| // ServeLater - l is really only for listeners that are | ||
| // tcpproxy.TargetListener or a derivative. Don't call after | ||
| // Serve() is called. | ||
| func (tps *InetAfTCPProxyServer) ServeLater(l net.Listener, s Server) { | ||
| tps.children = append(tps.children, &childProxy{l, s}) | ||
| } | ||
|
|
||
| func (tps *InetAfTCPProxyServer) Shutdown(ctx context.Context) error { | ||
| _ = tps.Proxy.Close() // always returns nil error anyway | ||
| firstErr := tps.Proxy.Wait() // wait for outer listener to close before telling the childProxy | ||
| errChan := make(chan error, len(tps.children)) | ||
|
nathanejohnson marked this conversation as resolved.
Outdated
|
||
| for _, sl := range tps.children { | ||
| go func(sl *childProxy) { | ||
| errChan <- sl.s.Shutdown(ctx) | ||
| }(sl) | ||
| } | ||
| for range tps.children { | ||
| err := <-errChan | ||
| if firstErr == nil { | ||
| firstErr = err | ||
| } | ||
| if err != nil { | ||
| log.Print("[ERROR] ", err) | ||
| } | ||
| } | ||
| return firstErr | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.