-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdestroy.go
66 lines (54 loc) · 1.97 KB
/
destroy.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
// Copyright 2015 The GoTor 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 main
type CircuitDestroyed struct {
NoBuffers
id CircuitID
reason DestroyReason
forRelay bool
truncate bool
}
func (c *CircuitDestroyed) CircID() CircuitID {
return c.id
}
func (data *CircuitDestroyed) ForRelay() bool {
return data.forRelay
}
func (data *CircuitDestroyed) Handle(c *OnionConnection, circ *Circuit) ActionableError {
Log(LOG_CIRC, "CircuitDestroy (front)")
if data.truncate {
panic("not implemented properly") // XXX needs cleanup of fields like nextHop/nextHopID
return c.sendRelayCell(circ, 0, BackwardDirection, RELAY_TRUNCATED, []byte{byte(data.reason)})
} else {
c.destroyCircuit(circ, false, true, data.reason)
c.writeQueue <- NewCell(c.negotiatedVersion, circ.id, CMD_DESTROY, []byte{byte(data.reason)}).Bytes()
return nil
}
}
func (data *CircuitDestroyed) HandleRelay(c *OnionConnection, circ *RelayCircuit) ActionableError {
Log(LOG_CIRC, "CircuitDestroy (relay)")
c.destroyRelayCircuit(circ, false, true, data.reason)
c.writeQueue <- NewCell(c.negotiatedVersion, circ.id, CMD_DESTROY, []byte{byte(data.reason)}).Bytes()
return nil
}
func (c *OnionConnection) handleDestroy(cell Cell) ActionableError {
Log(LOG_CIRC, "Got a destroy for circ %d with reason %s", cell.CircID(), DestroyReason(cell.Data()[0]))
circID := cell.CircID()
if circID.MSB(c.negotiatedVersion) != c.isOutbound {
circ, ok := c.circuits[circID]
if !ok {
Log(LOG_INFO, "Got a DESTROY but we don't know the circuit they're talking about. Ignoring")
} else {
c.destroyCircuit(circ, true, true, DestroyReason(cell.Data()[0]))
}
return nil
}
rcirc, ok := c.relayCircuits[circID]
if ok {
c.destroyRelayCircuit(rcirc, true, true, DestroyReason(cell.Data()[0]))
return nil
}
Log(LOG_INFO, "Got a DESTROY but we don't know the circuit they're talking about. Ignoring")
return nil
}