Exemple #1
0
func NewTunnel(client *C.struct_tcp_client, d dialer) (*TunIO, error) {
	destAddr := C.dump_dest_addr(client)
	defer C.free(unsafe.Pointer(destAddr))

	t := &TunIO{
		client:   &tcpClient{client: client},
		destAddr: C.GoString(destAddr),
		quit:     make(chan bool),
		doFlush:  make(chan bool, 256),
	}

	conn, err := d("tcp", t.destAddr)
	if err != nil {
		return nil, err
	}

	t.connOut = conn

	go func() {
		if err := t.reader(); err != nil {
			log.Printf("t.reader: %q", err)
		}
	}()

	go func() {
		if err := t.writer(); err != nil {
			log.Printf("t.writer: %q", err)
		}
	}()

	return t, nil
}
Exemple #2
0
// NewTunnel creates a tunnel to the destination indicated by client using the
// given dialer function.
func NewTunnel(client *C.struct_tcp_client, d dialer) (*TunIO, error) {
	destAddr := C.dump_dest_addr(client)
	defer C.free(unsafe.Pointer(destAddr))

	t := &TunIO{
		client:   &tcpClient{client: client},
		destAddr: C.GoString(destAddr),
		chunk:    make(chan []byte, 256),
	}

	t.SetStatus(StatusConnecting)

	var err error
	if t.connOut, err = d("tcp", t.destAddr); err != nil {
		t.SetStatus(StatusConnectionFailed)
		return nil, err
	}

	t.SetStatus(StatusConnected)

	return t, nil
}