/
handshake.go
43 lines (34 loc) · 1 KB
/
handshake.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
// Copyright ©2018 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xrootd // import "go-hep.org/x/hep/xrootd"
import (
"context"
"go-hep.org/x/hep/xrootd/internal/xrdenc"
"go-hep.org/x/hep/xrootd/xrdproto"
"go-hep.org/x/hep/xrootd/xrdproto/handshake"
)
func (sess *cliSession) handshake(ctx context.Context) error {
streamID := xrdproto.StreamID{0, 0}
responseChannel, err := sess.mux.ClaimWithID(streamID)
if err != nil {
return err
}
req := handshake.NewRequest()
var wBuffer xrdenc.WBuffer
err = req.MarshalXrd(&wBuffer)
if err != nil {
return err
}
resp, _, err := sess.send(ctx, streamID, responseChannel, wBuffer.Bytes(), nil, 0)
// TODO: should we react somehow to redirection?
if err != nil {
return err
}
var result handshake.Response
if err = result.UnmarshalXrd(xrdenc.NewRBuffer(resp)); err != nil {
return err
}
sess.protocolVersion = result.ProtocolVersion
return nil
}