| 117 | } |
| 118 | |
| 119 | func (c *Connection) Accept() error { |
| 120 | c.lock.Lock() |
| 121 | defer c.lock.Unlock() |
| 122 | if c.initiator { |
| 123 | return fmt.Errorf("cannot accept connection that was initiated locally") |
| 124 | } |
| 125 | if c.state != CONNECTION_STATE_WAITINIT { |
| 126 | return fmt.Errorf("invalid state, cannot accept connection in state %d", c.state) |
| 127 | } |
| 128 | c.state = CONNECTION_STATE_STARTED |
| 129 | c.stateCond.Broadcast() |
| 130 | packet := Packet{ |
| 131 | Type: PACKET_SUCCESS, |
| 132 | ConnectionId: c.id, |
| 133 | } |
| 134 | return c.ctx.writePacket(&packet) |
| 135 | } |
| 136 | |
| 137 | func (c *Connection) Reject() error { |
| 138 | c.lock.Lock() |