-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.go
84 lines (67 loc) · 1.79 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package rdp
import (
"bufio"
"fmt"
"net"
"time"
"github.com/kulaginds/rdp-html5/internal/pkg/rdp/fastpath"
"github.com/kulaginds/rdp-html5/internal/pkg/rdp/mcs"
"github.com/kulaginds/rdp-html5/internal/pkg/rdp/pdu"
"github.com/kulaginds/rdp-html5/internal/pkg/rdp/tpkt"
"github.com/kulaginds/rdp-html5/internal/pkg/rdp/x224"
)
type RemoteApp struct {
App string
WorkingDir string
Args string
}
type client struct {
conn net.Conn
buffReader *bufio.Reader
tpktLayer *tpkt.Protocol
x224Layer *x224.Protocol
mcsLayer *mcs.Protocol
fastPath *fastpath.Protocol
domain string
username string
password string
desktopWidth, desktopHeight uint16
serverCapabilitySets []pdu.CapabilitySet
remoteApp *RemoteApp
railState RailState
selectedProtocol pdu.NegotiationProtocol
serverNegotiationFlags pdu.NegotiationResponseFlag
channels []string
channelIDMap map[string]uint16
skipChannelJoin bool
shareID uint32
userID uint16
}
const (
tcpConnectionTimeout = 5 * time.Second
readBufferSize = 64 * 1024
)
func NewClient(
hostname, username, password string,
desktopWidth, desktopHeight int,
) (*client, error) {
c := client{
domain: "",
username: username,
password: password,
desktopWidth: uint16(desktopWidth),
desktopHeight: uint16(desktopHeight),
selectedProtocol: pdu.NegotiationProtocolSSL,
}
var err error
c.conn, err = net.DialTimeout("tcp", hostname, tcpConnectionTimeout)
if err != nil {
return nil, fmt.Errorf("tcp connect: %w", err)
}
c.buffReader = bufio.NewReaderSize(c.conn, readBufferSize)
c.tpktLayer = tpkt.New(&c)
c.x224Layer = x224.New(c.tpktLayer)
c.mcsLayer = mcs.New(c.x224Layer)
c.fastPath = fastpath.New(&c)
return &c, nil
}