Skip to content
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

STELLAR-3700 - Add option to disable TCP/UDP proxy for streams #137

Merged
merged 9 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/flag/proxy_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
defaultProxyProtocol = "udp"

// Supported proxy.
availableProxy = []string{"udp", "tcp"}
availableProxy = []string{"udp", "tcp", "disabled"}
danada marked this conversation as resolved.
Show resolved Hide resolved
// Default listen host for UDP.
defaultUDPListenHost = "127.0.0.1"
// Default listen port for UDP.
Expand Down Expand Up @@ -60,6 +60,7 @@ type ProxyFlags struct {

// Add flags to the command.
func (f *ProxyFlags) AddFlags(cmd *cobra.Command) {
//currently defaults to UDP
rockets3600 marked this conversation as resolved.
Show resolved Hide resolved
cmd.Flags().StringVarP(&f.ProxyProtocol, "proxy", "", defaultProxyProtocol,
"Proxy protocol. One of: "+strings.Join(availableProxy, "|"))

Expand Down Expand Up @@ -121,6 +122,12 @@ func (f *ProxyFlags) ToProxy() stream.Proxy {
log.Fatalf("could not open TCP proxy: %v\n", err)
}
return p
case "disabled":
p, err := stream.NewConnectionWithoutProxy()
if err != nil {
log.Fatalf("could not open connection: %v\n", err)
}
return p
}

log.Fatalf("unsupported proxy protocol: %v", protocol)
Expand Down
4 changes: 4 additions & 0 deletions cmd/satellite/open_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func NewOpenStreamCommand() *cobra.Command {
DelayThreshold: correctOrderFlags.DelayThreshold,
}

if proxyFlags.ProxyProtocol == "disabled" && writeFileFlag.FileName == "" {
log.Println("No proxy or output file set. Streamed data will be discarded")
}

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
defer close(c)
Expand Down
4 changes: 2 additions & 2 deletions docs/stellar_satellite_open-stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ stellar satellite open-stream [satellite-id] [flags]
### Options

```
--accepted-framing strings Framing type to receive. One of: IQ|IMAGE_PNG|IMAGE_JPEG|FREE_TEXT_UTF8|WATERFALL|BITSTREAM|AX25
--accepted-framing strings Framing type to receive. One of: BITSTREAM|AX25|IQ|IMAGE_PNG|IMAGE_JPEG|FREE_TEXT_UTF8|WATERFALL
--accepted-plan-id strings Plan ID(s) to accept data from.
--correct-order When set to true, packets will be sorted by time_first_byte_received. This feature is alpha quality.
--debug Output debug information. (default false)
Expand All @@ -24,7 +24,7 @@ stellar satellite open-stream [satellite-id] [flags]
--listen-host string Deprecated: use udp-listen-host instead.
--listen-port uint16 Deprecated: use udp-listen-port instead.
--output-file string [Alpha feature] The file to write packets to. Creates file if it does not exist; appends to file if it already exists. (default none)
--proxy string Proxy protocol. One of: udp|tcp (default "udp")
--proxy string Proxy protocol. One of: udp|tcp|disabled (default "udp")
--send-host string Deprecated: use udp-send-host instead.
--send-port uint16 Deprecated: use udp-send-port instead.
--stats [Alpha feature] Output telemetry stats information and generate pass summaries (default false)
Expand Down
63 changes: 63 additions & 0 deletions pkg/satellite/stream/disabled_proxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright © 2020 Infostellar, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package stream

type noProxy struct {
stream SatelliteStream
streamChan chan []byte
}

// Create a connection without using a proxy.
func NewConnectionWithoutProxy() (Proxy, error) {
streamChan := make(chan []byte)

p := &noProxy{
streamChan: streamChan,
}

return p, nil
}

// Start listening for packets to send to the satellite and sending back received packets.
func (p *noProxy) Start(o *SatelliteStreamOptions) (func(), error) {

var err error
var cleanup func()
p.stream, cleanup, err = OpenSatelliteStream(o, p.streamChan)
if err != nil {
return cleanup, err
}

go p.serve()

return cleanup, nil
}

func (p *noProxy) serve() {
for {
select {
case <-p.streamChan:
}
}
}

// Close the proxy.
danada marked this conversation as resolved.
Show resolved Hide resolved
func (p *noProxy) Close() error {
// Close the API stream.
close(p.streamChan)
p.stream.Close()

return nil
}