converge/pkg/comms/events.go
Erik Brakkee f0dd810541 many small changes
* removed the Async utility
* now using Ping message to webclient for keep alive instaed of actual content
* added remote shell to AgentInfo
* retry of connections to the agent
* better logging for SynchronizeStreams
2024-07-31 19:30:38 +02:00

114 lines
1.9 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
Shell string
}
type ClientInfo struct {
ClientId int
}
type SessionInfo struct {
ClientId string
// "ssh", "sftp"
SessionType string
}
type ExpiryTimeUpdate struct {
ExpiryTime time.Time
}
type HeartBeat struct {
// Empty
}
type ProtocolVersion struct {
Version int
}
type UserPassword struct {
Username string
Password string
}
// initialization mesaage when agent connects to server
type ServerInfo struct {
UserPassword UserPassword
}
// 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
}
// Generic wrapper message required to send messages of arbitrary type
type ConvergeMessage struct {
Value interface{}
}
func NewAgentInfo(shell string) AgentInfo {
username, _ := user.Current()
host, _ := os.Hostname()
pwd, _ := os.Getwd()
return AgentInfo{
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(AgentInfo{})
gob.Register(SessionInfo{})
gob.Register(ExpiryTimeUpdate{})
gob.Register(HeartBeat{})
// ConvergeServer to Agent
gob.Register(ProtocolVersion{})
gob.Register(UserPassword{})
// Wrapper event.
gob.Register(ConvergeMessage{})
}