Protocol version is now checked when the agent connects to the converge server. Next up: sending connection metadata and username password from server to agent and sending environment information back to the server. This means then that the side channel will only be used for expiry time messages and session type with the client id passed in so the converge server can than correlate the results back to the correct channel.
96 lines
1.6 KiB
Go
96 lines
1.6 KiB
Go
package comms
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"os"
|
|
"os/user"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
const PROTOCOL_VERSION = 1
|
|
|
|
func init() {
|
|
RegisterEventsWithGob()
|
|
}
|
|
|
|
// Client to server events
|
|
|
|
type AgentInfo struct {
|
|
Username string
|
|
Hostname string
|
|
Pwd string
|
|
OS string
|
|
}
|
|
|
|
type SessionInfo struct {
|
|
// "ssh", "sftp"
|
|
SessionType string
|
|
}
|
|
|
|
type ExpiryTimeUpdate struct {
|
|
ExpiryTime time.Time
|
|
}
|
|
|
|
type HeartBeat struct {
|
|
// Empty
|
|
}
|
|
|
|
// Message sent from converge server to agent
|
|
|
|
type ProtocolVersion struct {
|
|
Version int
|
|
}
|
|
|
|
type UserPassword struct {
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
type ConnectionInfo struct {
|
|
ConnectionId int
|
|
UserPassword UserPassword
|
|
}
|
|
|
|
// Generic wrapper message required to send messages of arbitrary type
|
|
|
|
type ConvergeMessage struct {
|
|
Value interface{}
|
|
}
|
|
|
|
func NewAgentInfo() AgentInfo {
|
|
username, _ := user.Current()
|
|
host, _ := os.Hostname()
|
|
pwd, _ := os.Getwd()
|
|
return AgentInfo{
|
|
Username: username.Username,
|
|
Hostname: host,
|
|
Pwd: pwd,
|
|
OS: runtime.GOOS,
|
|
}
|
|
}
|
|
|
|
func NewSessionInfo(sessionType string) SessionInfo {
|
|
return SessionInfo{SessionType: sessionType}
|
|
}
|
|
|
|
func NewExpiryTimeUpdate(expiryTime time.Time) ExpiryTimeUpdate {
|
|
return ExpiryTimeUpdate{ExpiryTime: expiryTime}
|
|
}
|
|
|
|
func RegisterEventsWithGob() {
|
|
// Agent to ConvergeServer
|
|
gob.Register(AgentInfo{})
|
|
gob.Register(SessionInfo{})
|
|
gob.Register(ExpiryTimeUpdate{})
|
|
gob.Register(HeartBeat{})
|
|
|
|
// ConvergeServer to Agent
|
|
gob.Register(ProtocolVersion{})
|
|
gob.Register(UserPassword{})
|
|
gob.Register(ConnectionInfo{})
|
|
|
|
// Wrapper event.
|
|
gob.Register(ConvergeMessage{})
|
|
}
|