forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pollhdlr.go
72 lines (69 loc) · 2.37 KB
/
pollhdlr.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
// Copyright 2017 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package base
import (
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/sig/disp"
"github.com/scionproto/scion/go/sig/mgmt"
"github.com/scionproto/scion/go/sig/sigcmn"
)
func PollReqHdlr() {
defer log.LogPanicAndExit()
log.Info("PollReqHdlr: starting")
for rpld := range disp.Dispatcher.PollReqC {
req, ok := rpld.P.(*mgmt.PollReq)
if !ok {
log.Error("PollReqHdlr: non-SIGPollReq payload received",
"src", rpld.Addr, "type", common.TypeOf(rpld.P), "Id", rpld.Id, "pld", rpld.P)
continue
}
//log.Debug("PollReqHdlr: got PollReq", "src", rpld.Addr, "pld", req)
spld, err := mgmt.NewPld(rpld.Id, mgmt.NewPollRep(sigcmn.MgmtAddr, req.Session))
if err != nil {
log.Error("PollReqHdlr: Error creating SIGCtrl payload", "err", err)
break
}
cpld, err := ctrl.NewPld(spld, nil)
if err != nil {
log.Error("PollReqHdlr: Error creating Ctrl payload", "err", err)
break
}
scpld, err := cpld.SignedPld(ctrl.NullSigner)
if err != nil {
log.Error("PollReqHdlr: Error creating signed Ctrl payload", "err", err)
break
}
raw, err := scpld.PackPld()
if err != nil {
log.Error("PollReqHdlr: Error packing signed Ctrl payload", "err", err)
break
}
l4 := addr.NewL4UDPInfo(req.Addr.Ctrl.Port)
sigCtrlAddr := &snet.Addr{
IA: rpld.Addr.IA,
Host: &addr.AppAddr{L3: req.Addr.Ctrl.Host(), L4: l4},
Path: rpld.Addr.Path,
NextHop: rpld.Addr.NextHop.Copy(),
}
_, err = sigcmn.CtrlConn.WriteToSCION(raw, sigCtrlAddr)
if err != nil {
log.Error("PollReqHdlr: Error sending Ctrl payload", "dest", rpld.Addr, "err", err)
}
}
log.Info("PollReqHdlr: stopped")
}