Now hijacking the ssh connection setup in the listener to exchange some information before passing the connection on to the SSH server. Next step is to do the full exchange of required information and to make it easy some simple Read and Write methods with timeouts are needed that use gob.
34 lines
740 B
Go
34 lines
740 B
Go
package comms
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"log"
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
type TCPChannel struct {
|
|
// can be any connection, including the ssh connnection before it is
|
|
// passed on to SSH during initialization of converge to agent communication
|
|
Peer net.Conn
|
|
Encoder *gob.Encoder
|
|
Decoder *gob.Decoder
|
|
}
|
|
|
|
// Synchronous functions with timeouts and error handling.
|
|
func (channel TCPChannel) SendAsync(object any, timeout time.Duration) error {
|
|
return nil
|
|
}
|
|
|
|
func (channel TCPChannel) ReceiveAsync(object any, timeout time.Duration) error {
|
|
return nil
|
|
}
|
|
|
|
func (channel TCPChannel) Send(object any) error {
|
|
err := channel.Encoder.Encode(ConvergeMessage{Value: object})
|
|
if err != nil {
|
|
log.Printf("Encoding error %v", err)
|
|
}
|
|
return err
|
|
}
|