Skip to content

Commit 02952d5

Browse files
committed
doc updates
1 parent 05cec92 commit 02952d5

File tree

11 files changed

+143
-217
lines changed

11 files changed

+143
-217
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# guac
22

3-
Guacamole client in Go.
3+
A Guacamole client in Go.
44

55
[![GoDoc](https://godoc.org/github.com/wwt/guac?status.svg)](http://godoc.org/github.com/wwt/guac)
66

77
## To run
8+
## Development
89

910
First start guacd in a container, for example:
1011

1112
```sh
1213
docker run --name guacd -d -p 4822:4822 guacamole/guacd
1314
```
1415

15-
Next, clone this repo and run provided main:
16+
Next run provided main:
1617

1718
```sh
1819
cd guac/cmd/guac
@@ -21,8 +22,9 @@ go run guac.go
2122

2223
Now you can connect with an example UI (coming soon)
2324

24-
## Acknowledgement
25+
## Acknowledgements
2526

26-
Initially forked from https://github.com/johnzhd/guacamole_client_go which is a direct rewrite of the Java Guacamole client.
27+
Initially forked from https://github.com/johnzhd/guacamole_client_go which is a direct rewrite of the Java Guacamole
28+
client. This project no longer resembles that one but it helped it get off the ground!
2729

28-
This project no longer resembles that one but it helped it get off the ground!
30+
Some of the comments are taken directly from the official Apache Guacamole Java client.

cmd/guac/guac.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func main() {
6868
// DemoDoConnect creates the tunnel to the remote machine (via guacd)
6969
func DemoDoConnect(request *http.Request) (guac.Tunnel, error) {
7070
config := guac.NewGuacamoleConfiguration()
71-
info := guac.NewGuacamoleClientInformation()
7271

7372
query := request.URL.Query()
7473
config.Protocol = query.Get("scheme")
@@ -79,20 +78,20 @@ func DemoDoConnect(request *http.Request) (guac.Tunnel, error) {
7978

8079
var err error
8180
if query.Get("width") != "" {
82-
info.OptimalScreenHeight, err = strconv.Atoi(query.Get("width"))
83-
if err != nil || info.OptimalScreenHeight == 0 {
81+
config.OptimalScreenHeight, err = strconv.Atoi(query.Get("width"))
82+
if err != nil || config.OptimalScreenHeight == 0 {
8483
logrus.Error("Invalid height")
85-
info.OptimalScreenHeight = 600
84+
config.OptimalScreenHeight = 600
8685
}
8786
}
8887
if query.Get("height") != "" {
89-
info.OptimalScreenWidth, err = strconv.Atoi(query.Get("height"))
90-
if err != nil || info.OptimalScreenWidth == 0 {
88+
config.OptimalScreenWidth, err = strconv.Atoi(query.Get("height"))
89+
if err != nil || config.OptimalScreenWidth == 0 {
9190
logrus.Error("Invalid width")
92-
info.OptimalScreenWidth = 800
91+
config.OptimalScreenWidth = 800
9392
}
9493
}
95-
info.AudioMimetypes = []string{"audio/L16", "rate=44100", "channels=2"}
94+
config.AudioMimetypes = []string{"audio/L16", "rate=44100", "channels=2"}
9695

9796
logrus.Debug("Connecting to guacd")
9897
addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:4822")
@@ -109,7 +108,7 @@ func DemoDoConnect(request *http.Request) (guac.Tunnel, error) {
109108
if request.URL.Query().Get("uuid") != "" {
110109
config.ConnectionID = request.URL.Query().Get("uuid")
111110
}
112-
err = stream.Handshake(config, info)
111+
err = stream.Handshake(config)
113112
if err != nil {
114113
return nil, err
115114
}

config.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
package guac
22

3+
// Config is the data sent to guacd to configure the session during the handshake.
34
type Config struct {
5+
// ConnectionID is used to reconnect to an existing session, otherwise leave blank for a new session.
46
ConnectionID string
7+
// Protocol is the protocol of the connection from guacd to the remote (rdp, ssh, etc).
58
Protocol string
9+
// Parameters are used to configure protocol specific options like sla for rdp or terminal color schemes.
610
Parameters map[string]string
7-
}
8-
9-
func NewGuacamoleConfiguration() *Config {
10-
return &Config{
11-
Parameters: make(map[string]string),
12-
}
13-
}
1411

15-
type ClientInfo struct {
12+
// OptimalScreenWidth is the desired width of the screen
1613
OptimalScreenWidth int
14+
// OptimalScreenHeight is the desired height of the screen
1715
OptimalScreenHeight int
16+
// OptimalResolution is the desired resolution of the screen
1817
OptimalResolution int
18+
// AudioMimetypes is an array of the supported audio types
1919
AudioMimetypes []string
20+
// VideoMimetypes is an array of the supported video types
2021
VideoMimetypes []string
22+
// ImageMimetypes is an array of the supported image types
2123
ImageMimetypes []string
2224
}
2325

24-
// NewGuacamoleClientInformation Construct function
25-
func NewGuacamoleClientInformation() *ClientInfo {
26-
return &ClientInfo{
26+
// NewGuacamoleConfiguration returns a Config with sane defaults
27+
func NewGuacamoleConfiguration() *Config {
28+
return &Config{
29+
Parameters: map[string]string{},
2730
OptimalScreenWidth: 1024,
2831
OptimalScreenHeight: 768,
2932
OptimalResolution: 96,

doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Package guac implements a HTTP client and a WebSocket client that connects to an Apache Guacamole server.
3+
*/
4+
package guac

mem_session.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ import (
55
"sync"
66
)
77

8+
// MemorySessionStore is a simple in-memory store of connected sessions that is used by
9+
// the WebsocketServer to store active sessions.
810
type MemorySessionStore struct {
911
sync.RWMutex
1012
ConnIds map[string]int
1113
}
1214

15+
// NewMemorySessionStore creates a new store
1316
func NewMemorySessionStore() *MemorySessionStore {
1417
return &MemorySessionStore{
1518
ConnIds: map[string]int{},
1619
}
1720
}
1821

22+
// Get returns a connection by uuid
1923
func (s *MemorySessionStore) Get(id string) int {
2024
s.RLock()
2125
defer s.RUnlock()
2226
return s.ConnIds[id]
2327
}
2428

29+
// Add inserts a new connection by uuid
2530
func (s *MemorySessionStore) Add(id string, req *http.Request) {
2631
s.Lock()
2732
defer s.Unlock()
@@ -35,6 +40,7 @@ func (s *MemorySessionStore) Add(id string, req *http.Request) {
3540
return
3641
}
3742

43+
// Delete removes a connection by uuid
3844
func (s *MemorySessionStore) Delete(id string, req *http.Request, tunnel Tunnel) {
3945
s.Lock()
4046
defer s.Unlock()

server.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const (
1616
uuidLength = 36
1717
)
1818

19-
// Server uses HTTP requests to talk to guacd
19+
// Server uses HTTP requests to talk to guacd (as opposed to WebSockets in ws_server.go)
2020
type Server struct {
21-
tunnels TunnelMap
21+
tunnels *TunnelMap
2222
connect func(*http.Request) (Tunnel, error)
2323
}
2424

@@ -30,28 +30,19 @@ func NewServer(connect func(r *http.Request) (Tunnel, error)) *Server {
3030
}
3131
}
3232

33-
/**
34-
* Registers the given tunnel such that future read/write requests to that
35-
* tunnel will be properly directed.
36-
*/
33+
// Registers the given tunnel such that future read/write requests to that tunnel will be properly directed.
3734
func (s *Server) registerTunnel(tunnel Tunnel) {
3835
s.tunnels.Put(tunnel.GetUUID(), tunnel)
3936
logger.Debugf("Registered tunnel \"%v\".", tunnel.GetUUID())
4037
}
4138

42-
/**
43-
* Deregisters the given tunnel such that future read/write requests to
44-
* that tunnel will be rejected.
45-
*/
39+
// Deregisters the given tunnel such that future read/write requests to that tunnel will be rejected.
4640
func (s *Server) deregisterTunnel(tunnel Tunnel) {
4741
s.tunnels.Remove(tunnel.GetUUID())
4842
logger.Debugf("Deregistered tunnel \"%v\".", tunnel.GetUUID())
4943
}
5044

51-
/**
52-
* Returns the tunnel with the given UUID, if it has been registered with
53-
* registerTunnel() and not yet deregistered with deregisterTunnel().
54-
*/
45+
// Returns the tunnel with the given UUID.
5546
func (s *Server) getTunnel(tunnelUUID string) (ret Tunnel, err error) {
5647
var ok bool
5748
ret, ok = s.tunnels.Get(tunnelUUID)
@@ -91,8 +82,7 @@ func (s *Server) handleTunnelRequestCore(response http.ResponseWriter, request *
9182
if len(query) == 0 {
9283
return ErrClient.NewError("No query string provided.")
9384
}
94-
// If connect operation, call doConnect() and return tunnel UUID
95-
// in response.
85+
// If connect operation, call doConnect() and return tunnel UUID in response.
9686
if query == "connect" {
9787
tunnel, e := s.connect(request)
9888

0 commit comments

Comments
 (0)