Merge lp:~ralsina/ubuntu-push/merge-automatic into lp:ubuntu-push
- merge-automatic
- Merge into trunk
Proposed by
Roberto Alsina
Status: | Merged |
---|---|
Approved by: | Roberto Alsina |
Approved revision: | no longer in the source branch. |
Merged at revision: | 125 |
Proposed branch: | lp:~ralsina/ubuntu-push/merge-automatic |
Merge into: | lp:ubuntu-push |
Diff against target: |
452 lines (+157/-89) 5 files modified
client/session/session.go (+25/-0) client/session/session_test.go (+105/-89) debian/changelog (+7/-0) protocol/messages.go (+14/-0) protocol/messages_test.go (+6/-0) |
To merge this branch: | bzr merge lp:~ralsina/ubuntu-push/merge-automatic |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Review via email: mp+232496@code.launchpad.net |
Commit message
Merge latest changes from automatic
Description of the change
Merge latest changes from automatic (for real this time)
To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) : | # |
review:
Approve
- 125. By Roberto Alsina
-
Merge latest changes from automatic
Approved by: Roberto Alsina
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'client/session/session.go' |
2 | --- client/session/session.go 2014-07-08 10:21:52 +0000 |
3 | +++ client/session/session.go 2014-08-28 15:08:25 +0000 |
4 | @@ -53,6 +53,7 @@ |
5 | protocol.BroadcastMsg |
6 | protocol.NotificationsMsg |
7 | protocol.ConnBrokenMsg |
8 | + protocol.SetParamsMsg |
9 | } |
10 | |
11 | // parseServerAddrSpec recognizes whether spec is a HTTP URL to get |
12 | @@ -130,6 +131,7 @@ |
13 | proto protocol.Protocol |
14 | pingInterval time.Duration |
15 | retrier util.AutoRedialer |
16 | + cookie string |
17 | // status |
18 | stateP *uint32 |
19 | ErrCh chan error |
20 | @@ -233,6 +235,18 @@ |
21 | return sess.Connection |
22 | } |
23 | |
24 | +func (sess *ClientSession) setCookie(cookie string) { |
25 | + sess.connLock.Lock() |
26 | + defer sess.connLock.Unlock() |
27 | + sess.cookie = cookie |
28 | +} |
29 | + |
30 | +func (sess *ClientSession) getCookie() string { |
31 | + sess.connLock.RLock() |
32 | + defer sess.connLock.RUnlock() |
33 | + return sess.cookie |
34 | +} |
35 | + |
36 | // getHosts sets deliveryHosts possibly querying a remote endpoint |
37 | func (sess *ClientSession) getHosts() error { |
38 | if sess.getHost != nil { |
39 | @@ -470,6 +484,14 @@ |
40 | return err |
41 | } |
42 | |
43 | +// handle "setparams" messages |
44 | +func (sess *ClientSession) handleSetParams(setParams *serverMsg) error { |
45 | + if setParams.SetCookie != "" { |
46 | + sess.setCookie(setParams.SetCookie) |
47 | + } |
48 | + return nil |
49 | +} |
50 | + |
51 | // loop runs the session with the server, emits a stream of events. |
52 | func (sess *ClientSession) loop() error { |
53 | var err error |
54 | @@ -492,6 +514,8 @@ |
55 | err = sess.handleNotifications(&recv) |
56 | case "connbroken": |
57 | err = sess.handleConnBroken(&recv) |
58 | + case "setparams": |
59 | + err = sess.handleSetParams(&recv) |
60 | case "warn": |
61 | // XXX: current message "warn" should be "connwarn" |
62 | fallthrough |
63 | @@ -533,6 +557,7 @@ |
64 | Type: "connect", |
65 | DeviceId: sess.DeviceId, |
66 | Authorization: sess.auth, |
67 | + Cookie: sess.getCookie(), |
68 | Levels: levels, |
69 | Info: sess.Info, |
70 | }) |
71 | |
72 | === modified file 'client/session/session_test.go' |
73 | --- client/session/session_test.go 2014-07-08 10:21:52 +0000 |
74 | +++ client/session/session_test.go 2014-08-28 15:08:25 +0000 |
75 | @@ -680,19 +680,20 @@ |
76 | ****************************************************************/ |
77 | |
78 | func (s *msgSuite) TestHandleBroadcastWorks(c *C) { |
79 | - msg := serverMsg{"broadcast", |
80 | - protocol.BroadcastMsg{ |
81 | - Type: "broadcast", |
82 | - AppId: "--ignored--", |
83 | - ChanId: "0", |
84 | - TopLevel: 2, |
85 | - Payloads: []json.RawMessage{ |
86 | - json.RawMessage(`{"img1/m1":[101,"tubular"]}`), |
87 | - json.RawMessage("false"), // shouldn't happen but robust |
88 | - json.RawMessage(`{"img1/m1":[102,"tubular"]}`), |
89 | - }, |
90 | - }, protocol.NotificationsMsg{}, protocol.ConnBrokenMsg{}} |
91 | - go func() { s.errCh <- s.sess.handleBroadcast(&msg) }() |
92 | + msg := new(serverMsg) |
93 | + msg.Type = "broadcast" |
94 | + msg.BroadcastMsg = protocol.BroadcastMsg{ |
95 | + Type: "broadcast", |
96 | + AppId: "--ignored--", |
97 | + ChanId: "0", |
98 | + TopLevel: 2, |
99 | + Payloads: []json.RawMessage{ |
100 | + json.RawMessage(`{"img1/m1":[101,"tubular"]}`), |
101 | + json.RawMessage("false"), // shouldn't happen but robust |
102 | + json.RawMessage(`{"img1/m1":[102,"tubular"]}`), |
103 | + }, |
104 | + } |
105 | + go func() { s.errCh <- s.sess.handleBroadcast(msg) }() |
106 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
107 | s.upCh <- nil // ack ok |
108 | c.Check(<-s.errCh, Equals, nil) |
109 | @@ -715,15 +716,16 @@ |
110 | } |
111 | |
112 | func (s *msgSuite) TestHandleBroadcastBadAckWrite(c *C) { |
113 | - msg := serverMsg{"broadcast", |
114 | - protocol.BroadcastMsg{ |
115 | - Type: "broadcast", |
116 | - AppId: "APP", |
117 | - ChanId: "0", |
118 | - TopLevel: 2, |
119 | - Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)}, |
120 | - }, protocol.NotificationsMsg{}, protocol.ConnBrokenMsg{}} |
121 | - go func() { s.errCh <- s.sess.handleBroadcast(&msg) }() |
122 | + msg := new(serverMsg) |
123 | + msg.Type = "broadcast" |
124 | + msg.BroadcastMsg = protocol.BroadcastMsg{ |
125 | + Type: "broadcast", |
126 | + AppId: "APP", |
127 | + ChanId: "0", |
128 | + TopLevel: 2, |
129 | + Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)}, |
130 | + } |
131 | + go func() { s.errCh <- s.sess.handleBroadcast(msg) }() |
132 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
133 | failure := errors.New("ACK ACK ACK") |
134 | s.upCh <- failure |
135 | @@ -732,15 +734,16 @@ |
136 | } |
137 | |
138 | func (s *msgSuite) TestHandleBroadcastWrongChannel(c *C) { |
139 | - msg := serverMsg{"broadcast", |
140 | - protocol.BroadcastMsg{ |
141 | - Type: "broadcast", |
142 | - AppId: "APP", |
143 | - ChanId: "something awful", |
144 | - TopLevel: 2, |
145 | - Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)}, |
146 | - }, protocol.NotificationsMsg{}, protocol.ConnBrokenMsg{}} |
147 | - go func() { s.errCh <- s.sess.handleBroadcast(&msg) }() |
148 | + msg := new(serverMsg) |
149 | + msg.Type = "brodacast" |
150 | + msg.BroadcastMsg = protocol.BroadcastMsg{ |
151 | + Type: "broadcast", |
152 | + AppId: "APP", |
153 | + ChanId: "something awful", |
154 | + TopLevel: 2, |
155 | + Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)}, |
156 | + } |
157 | + go func() { s.errCh <- s.sess.handleBroadcast(msg) }() |
158 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
159 | s.upCh <- nil // ack ok |
160 | c.Check(<-s.errCh, IsNil) |
161 | @@ -749,15 +752,16 @@ |
162 | |
163 | func (s *msgSuite) TestHandleBroadcastBrokenSeenState(c *C) { |
164 | s.sess.SeenState = &brokenSeenState{} |
165 | - msg := serverMsg{"broadcast", |
166 | - protocol.BroadcastMsg{ |
167 | - Type: "broadcast", |
168 | - AppId: "--ignored--", |
169 | - ChanId: "0", |
170 | - TopLevel: 2, |
171 | - Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)}, |
172 | - }, protocol.NotificationsMsg{}, protocol.ConnBrokenMsg{}} |
173 | - go func() { s.errCh <- s.sess.handleBroadcast(&msg) }() |
174 | + msg := new(serverMsg) |
175 | + msg.Type = "broadcast" |
176 | + msg.BroadcastMsg = protocol.BroadcastMsg{ |
177 | + Type: "broadcast", |
178 | + AppId: "--ignored--", |
179 | + ChanId: "0", |
180 | + TopLevel: 2, |
181 | + Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)}, |
182 | + } |
183 | + go func() { s.errCh <- s.sess.handleBroadcast(msg) }() |
184 | s.upCh <- nil // ack ok |
185 | // start returns with error |
186 | c.Check(<-s.errCh, Not(Equals), nil) |
187 | @@ -772,9 +776,8 @@ |
188 | func (s *msgSuite) TestHandleBroadcastClearsDelay(c *C) { |
189 | s.sess.setShouldDelay() |
190 | |
191 | - msg := serverMsg{"broadcast", protocol.BroadcastMsg{}, |
192 | - protocol.NotificationsMsg{}, protocol.ConnBrokenMsg{}} |
193 | - go func() { s.errCh <- s.sess.handleBroadcast(&msg) }() |
194 | + msg := &serverMsg{Type: "broadcast"} |
195 | + go func() { s.errCh <- s.sess.handleBroadcast(msg) }() |
196 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
197 | s.upCh <- nil // ack ok |
198 | c.Check(<-s.errCh, IsNil) |
199 | @@ -785,9 +788,8 @@ |
200 | func (s *msgSuite) TestHandleBroadcastDoesNotClearDelayOnError(c *C) { |
201 | s.sess.setShouldDelay() |
202 | |
203 | - msg := serverMsg{"broadcast", protocol.BroadcastMsg{}, |
204 | - protocol.NotificationsMsg{}, protocol.ConnBrokenMsg{}} |
205 | - go func() { s.errCh <- s.sess.handleBroadcast(&msg) }() |
206 | + msg := &serverMsg{Type: "broadcast"} |
207 | + go func() { s.errCh <- s.sess.handleBroadcast(msg) }() |
208 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
209 | s.upCh <- errors.New("bcast") |
210 | c.Check(<-s.errCh, NotNil) |
211 | @@ -835,12 +837,12 @@ |
212 | MsgId: "b", |
213 | Payload: json.RawMessage(`{"m": 2}`), |
214 | } |
215 | - msg := serverMsg{"notifications", |
216 | - protocol.BroadcastMsg{}, |
217 | - protocol.NotificationsMsg{ |
218 | - Notifications: []protocol.Notification{n1, n2}, |
219 | - }, protocol.ConnBrokenMsg{}} |
220 | - go func() { s.errCh <- s.sess.handleNotifications(&msg) }() |
221 | + msg := new(serverMsg) |
222 | + msg.Type = "notifications" |
223 | + msg.NotificationsMsg = protocol.NotificationsMsg{ |
224 | + Notifications: []protocol.Notification{n1, n2}, |
225 | + } |
226 | + go func() { s.errCh <- s.sess.handleNotifications(msg) }() |
227 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
228 | s.upCh <- nil // ack ok |
229 | c.Check(<-s.errCh, Equals, nil) |
230 | @@ -881,12 +883,12 @@ |
231 | MsgId: "b", |
232 | Payload: json.RawMessage(`{"m": 2}`), |
233 | } |
234 | - msg := serverMsg{"notifications", |
235 | - protocol.BroadcastMsg{}, |
236 | - protocol.NotificationsMsg{ |
237 | - Notifications: []protocol.Notification{n1, n2}, |
238 | - }, protocol.ConnBrokenMsg{}} |
239 | - go func() { s.errCh <- s.sess.handleNotifications(&msg) }() |
240 | + msg := new(serverMsg) |
241 | + msg.Type = "notifications" |
242 | + msg.NotificationsMsg = protocol.NotificationsMsg{ |
243 | + Notifications: []protocol.Notification{n1, n2}, |
244 | + } |
245 | + go func() { s.errCh <- s.sess.handleNotifications(msg) }() |
246 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
247 | s.upCh <- nil // ack ok |
248 | c.Check(<-s.errCh, Equals, nil) |
249 | @@ -916,12 +918,12 @@ |
250 | MsgId: "b", |
251 | Payload: json.RawMessage(`{"m": 2}`), |
252 | } |
253 | - msg := serverMsg{"notifications", |
254 | - protocol.BroadcastMsg{}, |
255 | - protocol.NotificationsMsg{ |
256 | - Notifications: []protocol.Notification{n1, n2}, |
257 | - }, protocol.ConnBrokenMsg{}} |
258 | - go func() { s.errCh <- s.sess.handleNotifications(&msg) }() |
259 | + msg := new(serverMsg) |
260 | + msg.Type = "notifications" |
261 | + msg.NotificationsMsg = protocol.NotificationsMsg{ |
262 | + Notifications: []protocol.Notification{n1, n2}, |
263 | + } |
264 | + go func() { s.errCh <- s.sess.handleNotifications(msg) }() |
265 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
266 | s.upCh <- nil // ack ok |
267 | c.Check(<-s.errCh, Equals, nil) |
268 | @@ -941,7 +943,7 @@ |
269 | c.Check(ac.ops, HasLen, 3) |
270 | |
271 | // second time they get ignored |
272 | - go func() { s.errCh <- s.sess.handleNotifications(&msg) }() |
273 | + go func() { s.errCh <- s.sess.handleNotifications(msg) }() |
274 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
275 | s.upCh <- nil // ack ok |
276 | c.Check(<-s.errCh, Equals, nil) |
277 | @@ -956,12 +958,12 @@ |
278 | MsgId: "a", |
279 | Payload: json.RawMessage(`{"m": 1}`), |
280 | } |
281 | - msg := serverMsg{"notifications", |
282 | - protocol.BroadcastMsg{}, |
283 | - protocol.NotificationsMsg{ |
284 | - Notifications: []protocol.Notification{n1}, |
285 | - }, protocol.ConnBrokenMsg{}} |
286 | - go func() { s.errCh <- s.sess.handleNotifications(&msg) }() |
287 | + msg := new(serverMsg) |
288 | + msg.Type = "notifications" |
289 | + msg.NotificationsMsg = protocol.NotificationsMsg{ |
290 | + Notifications: []protocol.Notification{n1}, |
291 | + } |
292 | + go func() { s.errCh <- s.sess.handleNotifications(msg) }() |
293 | c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"}) |
294 | failure := errors.New("ACK ACK ACK") |
295 | s.upCh <- failure |
296 | @@ -979,12 +981,12 @@ |
297 | MsgId: "a", |
298 | Payload: json.RawMessage(`{"m": 1}`), |
299 | } |
300 | - msg := serverMsg{"notifications", |
301 | - protocol.BroadcastMsg{}, |
302 | - protocol.NotificationsMsg{ |
303 | - Notifications: []protocol.Notification{n1}, |
304 | - }, protocol.ConnBrokenMsg{}} |
305 | - go func() { s.errCh <- s.sess.handleNotifications(&msg) }() |
306 | + msg := new(serverMsg) |
307 | + msg.Type = "notifications" |
308 | + msg.NotificationsMsg = protocol.NotificationsMsg{ |
309 | + Notifications: []protocol.Notification{n1}, |
310 | + } |
311 | + go func() { s.errCh <- s.sess.handleNotifications(msg) }() |
312 | s.upCh <- nil // ack ok |
313 | // start returns with error |
314 | c.Check(<-s.errCh, Not(Equals), nil) |
315 | @@ -1003,26 +1005,24 @@ |
316 | ****************************************************************/ |
317 | |
318 | func (s *msgSuite) TestHandleConnBrokenUnkwown(c *C) { |
319 | - msg := serverMsg{"connbroken", |
320 | - protocol.BroadcastMsg{}, protocol.NotificationsMsg{}, |
321 | - protocol.ConnBrokenMsg{ |
322 | - Reason: "REASON", |
323 | - }, |
324 | + msg := new(serverMsg) |
325 | + msg.Type = "connbroken" |
326 | + msg.ConnBrokenMsg = protocol.ConnBrokenMsg{ |
327 | + Reason: "REASON", |
328 | } |
329 | - go func() { s.errCh <- s.sess.handleConnBroken(&msg) }() |
330 | + go func() { s.errCh <- s.sess.handleConnBroken(msg) }() |
331 | c.Check(<-s.errCh, ErrorMatches, "server broke connection: REASON") |
332 | c.Check(s.sess.State(), Equals, Error) |
333 | } |
334 | |
335 | func (s *msgSuite) TestHandleConnBrokenHostMismatch(c *C) { |
336 | - msg := serverMsg{"connbroken", |
337 | - protocol.BroadcastMsg{}, protocol.NotificationsMsg{}, |
338 | - protocol.ConnBrokenMsg{ |
339 | - Reason: protocol.BrokenHostMismatch, |
340 | - }, |
341 | + msg := new(serverMsg) |
342 | + msg.Type = "connbroken" |
343 | + msg.ConnBrokenMsg = protocol.ConnBrokenMsg{ |
344 | + Reason: protocol.BrokenHostMismatch, |
345 | } |
346 | s.sess.deliveryHosts = []string{"foo:443", "bar:443"} |
347 | - go func() { s.errCh <- s.sess.handleConnBroken(&msg) }() |
348 | + go func() { s.errCh <- s.sess.handleConnBroken(msg) }() |
349 | c.Check(<-s.errCh, ErrorMatches, "server broke connection: host-mismatch") |
350 | c.Check(s.sess.State(), Equals, Error) |
351 | // hosts were reset |
352 | @@ -1113,6 +1113,20 @@ |
353 | c.Check(<-s.errCh, Equals, failure) |
354 | } |
355 | |
356 | +func (s *loopSuite) TestLoopSetParams(c *C) { |
357 | + c.Check(s.sess.State(), Equals, Running) |
358 | + setParams := protocol.SetParamsMsg{ |
359 | + Type: "setparams", |
360 | + SetCookie: "COOKIE", |
361 | + } |
362 | + c.Check(takeNext(s.downCh), Equals, "deadline 1ms") |
363 | + s.upCh <- setParams |
364 | + failure := errors.New("fail") |
365 | + s.upCh <- failure |
366 | + c.Assert(<-s.errCh, Equals, failure) |
367 | + c.Check(s.sess.getCookie(), Equals, "COOKIE") |
368 | +} |
369 | + |
370 | func (s *loopSuite) TestLoopConnBroken(c *C) { |
371 | c.Check(s.sess.State(), Equals, Running) |
372 | broken := protocol.ConnBrokenMsg{ |
373 | @@ -1302,6 +1316,7 @@ |
374 | sess, err := NewSession("", conf, "wah", cs.lvls, cs.log) |
375 | c.Assert(err, IsNil) |
376 | sess.Connection = &testConn{Name: "TestStartWorks"} |
377 | + sess.setCookie("COOKIE") |
378 | errCh := make(chan error, 1) |
379 | upCh := make(chan interface{}, 5) |
380 | downCh := make(chan interface{}, 5) |
381 | @@ -1317,6 +1332,7 @@ |
382 | c.Check(ok, Equals, true) |
383 | c.Check(msg.DeviceId, Equals, "wah") |
384 | c.Check(msg.Authorization, Equals, "") |
385 | + c.Check(msg.Cookie, Equals, "COOKIE") |
386 | c.Check(msg.Info, DeepEquals, info) |
387 | upCh <- nil // no error |
388 | upCh <- protocol.ConnAckMsg{ |
389 | |
390 | === modified file 'debian/changelog' |
391 | --- debian/changelog 2014-08-27 18:47:25 +0000 |
392 | +++ debian/changelog 2014-08-28 15:08:25 +0000 |
393 | @@ -1,3 +1,10 @@ |
394 | +ubuntu-push (0.63.1) UNRELEASED; urgency=medium |
395 | + |
396 | + [ Samuele Pedroni ] |
397 | + * Support taking a cookie from the server and sending it back on connect (feature was incomplete). |
398 | + |
399 | + -- Roberto Alsina <ralsina@yoga> Thu, 28 Aug 2014 12:07:01 -0300 |
400 | + |
401 | ubuntu-push (0.63+14.10.20140827-0ubuntu1) utopic; urgency=medium |
402 | |
403 | [ Samuele Pedroni ] |
404 | |
405 | === modified file 'protocol/messages.go' |
406 | --- protocol/messages.go 2014-05-15 16:36:45 +0000 |
407 | +++ protocol/messages.go 2014-08-28 15:08:25 +0000 |
408 | @@ -32,6 +32,7 @@ |
409 | ClientVer string |
410 | DeviceId string |
411 | Authorization string |
412 | + Cookie string |
413 | Info map[string]interface{} `json:",omitempty"` // platform etc... |
414 | // maps channel ids (hex encoded UUIDs) to known client channel levels |
415 | Levels map[string]int64 |
416 | @@ -103,6 +104,19 @@ |
417 | WarnUnauthorized = "unauthorized" |
418 | ) |
419 | |
420 | +// SETPARAMS message |
421 | +type SetParamsMsg struct { |
422 | + Type string `json:"T"` |
423 | + SetCookie string |
424 | +} |
425 | + |
426 | +func (m *SetParamsMsg) Split() bool { |
427 | + return true |
428 | +} |
429 | +func (m *SetParamsMsg) OnewayContinue() bool { |
430 | + return true |
431 | +} |
432 | + |
433 | // PING/PONG messages |
434 | type PingPongMsg struct { |
435 | Type string `json:"T"` |
436 | |
437 | === modified file 'protocol/messages_test.go' |
438 | --- protocol/messages_test.go 2014-05-15 16:36:45 +0000 |
439 | +++ protocol/messages_test.go 2014-08-28 15:08:25 +0000 |
440 | @@ -118,6 +118,12 @@ |
441 | c.Check(m.OnewayContinue(), Equals, true) |
442 | } |
443 | |
444 | +func (s *messagesSuite) TestSetParamsMsg(c *C) { |
445 | + m := &SetParamsMsg{} |
446 | + c.Check(m.Split(), Equals, true) |
447 | + c.Check(m.OnewayContinue(), Equals, true) |
448 | +} |
449 | + |
450 | func (s *messagesSuite) TestExtractPayloads(c *C) { |
451 | c.Check(ExtractPayloads(nil), IsNil) |
452 | p1 := json.RawMessage(`{"a":1}`) |