-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
183 lines (151 loc) · 3.31 KB
/
message.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package sunrpc
import (
"sync/atomic"
"time"
)
//
// Authorization Data
//
// AuthFlavor is an enumeration of all supported authentication flavors.
type AuthFlavor int32
// All possible authentication flavors.
const (
AuthFlavorNone AuthFlavor = iota
AuthFlavorUnix
AuthFlavorDes
)
type OpaqueAuth struct {
Flavor AuthFlavor
Body []byte // Must be between 0 and 400 bytes
}
type AuthNone struct{}
type AuthUnix struct {
Stamp uint32
MachineName string
Uid, Gid uint32
Gids []uint32
}
//
// RPC Message
//
// MessageType is an enumeration of all possible RPC message types.
type MessageType int32
// All possible RPC message types.
const (
Call MessageType = 0
Reply MessageType = 1
)
// Message is an RPC message header.
type Message struct {
Xid uint32
Type MessageType
}
//
// Call
//
// CallBody is the body of an RPC "Call" message.
type CallBody struct {
RPCVersion uint32
Program uint32
Version uint32
Procedure uint32
Cred OpaqueAuth
Verf OpaqueAuth
}
//
// Reply
//
// ReplyType is the kind of RPC "reply" message.
type ReplyType int32
// Enumeration of all possible RPC replies.
const (
Accepted ReplyType = 0
Denied ReplyType = 1
InvalidReplyType ReplyType = -1
)
type ReplyBody struct {
Type ReplyType
}
// AcceptType is used to tell the client how the server accepted an RPC call.
type AcceptType int32
// Enumeration of all possible RPC "Accept" messages.
const (
Success AcceptType = 0
ProgUnavail = 1
ProgMismatch = 2
ProcUnavail = 3
GarbageArgs = 4
SystemErr = 5
)
// AcceptedReply is the
type AcceptedReply struct {
Verf OpaqueAuth
Type AcceptType
}
type RejectStat uint32
const (
RpcMismatch RejectStat = 0
AuthError = 1
NoReject RejectStat = 0xFFFFFFFF
)
type AuthStat uint32
const (
AuthBadCred AuthStat = iota
AuthRejectedCred
AuthBadVerf
AUthRejectedVerf
AuthTooWeak
)
type RejectedReply struct {
Stat RejectStat
}
type ProgMismatchReply struct {
Low uint
High uint
}
//
// Convenience: Procedure Call
//
// ProcedureCall combines the RPC Message header with RPC Call body (except for function arguments)
// for convenience during (de)serialization.
type ProcedureCall struct {
Header Message
Body CallBody
}
// ProcedureReply is the reply to a procedure call
type ProcedureReply struct {
Header Message
Type ReplyType `xdr:"union"`
Accepted struct {
Verf OpaqueAuth
Stat AcceptType `xdr:"union"`
MismatchInfo struct {
Low, High uint32
} `xdr:"unioncase=2"` // ProgMismatch
// results follow here
} `xdr:"unioncase=0"`
Rejected struct {
Stat RejectStat `xdr:"union"`
MismatchInfo struct {
Low, High uint32
} `xdr:"unioncase=0"` // RpcMismatch
AuthStat AuthStat `xdr:"unioncase=0"` // AuthError
} `xdr:"unioncase=1"`
}
var xidCounter = int32(time.Now().UnixNano())
// NewProcedureCall creates a new RPC call packet with a transaction ID derived from the current
// UNIX time stamp.
func NewProcedureCall(program uint32, version uint32, procedure uint32) *ProcedureCall {
return &ProcedureCall{
Header: Message{
Xid: uint32(atomic.AddInt32(&xidCounter, 1)),
Type: Call,
},
Body: CallBody{
RPCVersion: 2,
Program: program,
Version: version,
Procedure: procedure,
},
}
}