-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new phenix-tunneler exe to tunnel port forwards using WebSockets
- Loading branch information
1 parent
d65ab2c
commit 6370ff5
Showing
44 changed files
with
2,888 additions
and
882 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
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
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,129 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/gob" | ||
"fmt" | ||
"math/rand" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type client struct { | ||
conn net.Conn | ||
|
||
enc *gob.Encoder | ||
dec *gob.Decoder | ||
} | ||
|
||
func newClient() (*client, error) { | ||
var ( | ||
sockDir = filepath.Join(os.TempDir(), "phenix") | ||
sockPath = filepath.Join(sockDir, "tunneler.sock") | ||
|
||
err error | ||
) | ||
|
||
cli := new(client) | ||
|
||
cli.conn, err = net.Dial("unix", sockPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("dialing phenix unix socket %s: %w", sockPath, err) | ||
} | ||
|
||
cli.enc = gob.NewEncoder(cli.conn) | ||
cli.dec = gob.NewDecoder(cli.conn) | ||
|
||
return cli, nil | ||
} | ||
|
||
func (this client) close() error { | ||
return this.conn.Close() | ||
} | ||
|
||
func (this client) getLocalListeners() (Listeners, error) { | ||
msg := Message{ | ||
MID: rand.Int(), | ||
Type: LISTENERS, | ||
} | ||
|
||
if err := this.enc.Encode(msg); err != nil { | ||
return nil, fmt.Errorf("sending request: %w", err) | ||
} | ||
|
||
if err := this.dec.Decode(&msg); err != nil { | ||
return nil, fmt.Errorf("receiving response: %w", err) | ||
} | ||
|
||
if payload, ok := msg.Payload.(Listeners); ok { | ||
return payload, nil | ||
} else { | ||
return nil, fmt.Errorf("decoding listeners from response") | ||
} | ||
} | ||
|
||
func (this client) moveLocalListener(id, port int) error { | ||
msg := Message{ | ||
MID: rand.Int(), | ||
Type: MOVE, | ||
Payload: []int{id, port}, | ||
} | ||
|
||
if err := this.enc.Encode(msg); err != nil { | ||
return fmt.Errorf("sending request: %w", err) | ||
} | ||
|
||
if err := this.dec.Decode(&msg); err != nil { | ||
return fmt.Errorf("receiving response: %w", err) | ||
} | ||
|
||
if msg.Error != "" { | ||
return fmt.Errorf(msg.Error) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (this client) activateLocalListener(id int) error { | ||
msg := Message{ | ||
MID: rand.Int(), | ||
Type: ACTIVATE, | ||
Payload: id, | ||
} | ||
|
||
if err := this.enc.Encode(msg); err != nil { | ||
return fmt.Errorf("sending request: %w", err) | ||
} | ||
|
||
if err := this.dec.Decode(&msg); err != nil { | ||
return fmt.Errorf("receiving response: %w", err) | ||
} | ||
|
||
if msg.Error != "" { | ||
return fmt.Errorf(msg.Error) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (this client) deactivateLocalListener(id int) error { | ||
msg := Message{ | ||
MID: rand.Int(), | ||
Type: DEACTIVATE, | ||
Payload: id, | ||
} | ||
|
||
if err := this.enc.Encode(msg); err != nil { | ||
return fmt.Errorf("sending request: %w", err) | ||
} | ||
|
||
if err := this.dec.Decode(&msg); err != nil { | ||
return fmt.Errorf("receiving response: %w", err) | ||
} | ||
|
||
if msg.Error != "" { | ||
return fmt.Errorf(msg.Error) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.