converge/pkg/comms/events.go
Erik Brakkee a3fe2fbcb6 hostkey is now sent from the server to the agent so that at a later
stage we can make the hostkey conrfigurable at the server level instead
of using a fixed hardcoded key.
2024-08-17 21:35:29 +02:00

118 lines
2.0 KiB
Go

package comms
import (
"encoding/gob"
"os"
"os/user"
"runtime"
"time"
)
const PROTOCOL_VERSION = 4
func init() {
RegisterEventsWithGob()
}
// Agent to server events
type EnvironmentInfo struct {
Username string
Hostname string
Pwd string
OS string
Shell string
}
type ClientInfo struct {
ClientId string
}
type SessionInfo struct {
ClientId string
// "ssh", "sftp"
SessionType string
}
type ExpiryTimeUpdate struct {
ExpiryTime time.Time
}
type HeartBeat struct {
// Empty
}
type ProtocolVersion struct {
Version int
}
// initialization mesaage when agent connects to server
type ServerInfo struct {
}
// confirmation message when agent connects
type AgentRegistration struct {
Ok bool
Message string
// final Id assigned by the server. Usually identical to the requested id
// but if there is a conflict, a new id is chosen.
Id string
HostPrivateKey []byte
}
// Generic wrapper message required to send messages of arbitrary type
type ConvergeMessage struct {
Value interface{}
}
func NewEnvironmentInfo(shell string) EnvironmentInfo {
username, _ := user.Current()
host, _ := os.Hostname()
pwd, _ := os.Getwd()
return EnvironmentInfo{
Username: username.Username,
Hostname: host,
Pwd: pwd,
OS: runtime.GOOS,
Shell: shell,
}
}
func NewSessionInfo(clientId, sessionType string) SessionInfo {
return SessionInfo{
ClientId: clientId,
SessionType: sessionType,
}
}
func NewExpiryTimeUpdate(expiryTime time.Time) ExpiryTimeUpdate {
return ExpiryTimeUpdate{ExpiryTime: expiryTime}
}
func RegisterEventsWithGob() {
// Agent to ConvergeServer
gob.Register(EnvironmentInfo{})
gob.Register(SessionInfo{})
gob.Register(ExpiryTimeUpdate{})
gob.Register(HeartBeat{})
// ConvergeServer to Agent and client
gob.Register(ProtocolVersion{})
// ConvergeServer to Client
gob.Register(ClientConnectionInfo{})
// Wrapper event.
gob.Register(ConvergeMessage{})
}
// Server to client events
type ClientConnectionInfo struct {
Ok bool
Message string
}