refactor: add a rw mutex lock to all getter/setter methods
This commit is contained in:
parent
cd50bf0b39
commit
2bb558f878
12
net/ws.go
12
net/ws.go
|
@ -119,6 +119,8 @@ func (p *WebSocketPeer) End() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (p *WebSocketPeer) EndForAbuse() error {
|
func (p *WebSocketPeer) EndForAbuse() error {
|
||||||
|
p.BasePeer.lock.Lock()
|
||||||
|
defer p.BasePeer.lock.Unlock()
|
||||||
p.abuser = true
|
p.abuser = true
|
||||||
err := p.socket.Close(websocket.StatusPolicyViolation, "")
|
err := p.socket.Close(websocket.StatusPolicyViolation, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -128,10 +130,14 @@ func (p *WebSocketPeer) EndForAbuse() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (p *WebSocketPeer) SetId(id *encoding.NodeId) {
|
func (p *WebSocketPeer) SetId(id *encoding.NodeId) {
|
||||||
|
p.BasePeer.lock.Lock()
|
||||||
|
defer p.BasePeer.lock.Unlock()
|
||||||
p.id = id
|
p.id = id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebSocketPeer) SetChallenge(challenge []byte) {
|
func (p *WebSocketPeer) SetChallenge(challenge []byte) {
|
||||||
|
p.BasePeer.lock.Lock()
|
||||||
|
defer p.BasePeer.lock.Unlock()
|
||||||
p.challenge = challenge
|
p.challenge = challenge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +146,8 @@ func (p *WebSocketPeer) GetChallenge() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebSocketPeer) GetIP() net.Addr {
|
func (p *WebSocketPeer) GetIP() net.Addr {
|
||||||
|
p.BasePeer.lock.Lock()
|
||||||
|
defer p.BasePeer.lock.Unlock()
|
||||||
if p.ip != nil {
|
if p.ip != nil {
|
||||||
return p.ip
|
return p.ip
|
||||||
}
|
}
|
||||||
|
@ -155,6 +163,8 @@ func (p *WebSocketPeer) GetIP() net.Addr {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebSocketPeer) SetIP(ip net.Addr) {
|
func (p *WebSocketPeer) SetIP(ip net.Addr) {
|
||||||
|
p.BasePeer.lock.Lock()
|
||||||
|
defer p.BasePeer.lock.Unlock()
|
||||||
p.ip = ip
|
p.ip = ip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,5 +173,7 @@ func (b *WebSocketPeer) GetIPString() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebSocketPeer) Abuser() bool {
|
func (p *WebSocketPeer) Abuser() bool {
|
||||||
|
p.BasePeer.lock.Lock()
|
||||||
|
defer p.BasePeer.lock.Unlock()
|
||||||
return p.abuser
|
return p.abuser
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue