jpillora / jpillora/chisel

Be able to wait until client SSH tunnel is established

Open
#319 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
16.6k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

I would like to use chisel client and block or get notified when the SSH tunnel is ready to send/receive data.

I would like to be able to do something like this:

import (
  "context"
  "time"
  chclient "github.com/jpillora/chisel/client"
)

func main(){
  config := chclient.Config(
    KeepAlive: time.Second,
    MaxRetryInterval: time.Second,
    Server: "my-chisel-server",
    Remotes:  []string{"1234:localhost:1234"}
  }

  established := make(chan bool)
  c, err := chclient.NewClient(&config)
  if err != nil {
    log.Fatal(err)
  }
  go func() {
    ctx, cancel = context.WithCancel(context.Background())
    defer cancel()
    if err := c.Start(ctx); err != nil {
      log.Fatal(err)
    }
    
    go func(ctx context.Context) {
      <-ctx.Done()
      // connection failed
      log.Fatal(ctx.Error())
    }(ctx)

    go func() {
      // GetTunnelSSHConn bloquea hasta que está establecida la conexión
      sshCon := c.GetTunnelSSHConn(ctx)
      if (sshCon != nil) {
        log.Printf("Connection established")
        // NOW WE CAN SEND/RECEIVE DATA
       }
    }()

    c.Wait()  // <-- this waits until client is closed or context is cancelled
  }()

  // wait until connection established
  if (<- established) {
    // now I am sure connection has been established and can use tunnel
  }
}

To be able to do this, we would need to expose the internal tunnel inside Client, and use the (private) function getSSH that blocks until connection is established.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the chisel client package at Client, its internal tunnel, and the private getSSH function mentioned in the issue. Trace how Start and Wait establish or lose connections, then define an exposed blocking or notification mechanism whose done condition is that the SSH tunnel is ready for data transfer.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.