add mutex to guard session's peer's metadata changing
This commit is contained in:
parent
92a3299f16
commit
68437c8c69
2 changed files with 8 additions and 4 deletions
|
@ -61,7 +61,8 @@ func parseLine(line string) (cmd command) {
|
|||
}
|
||||
|
||||
func (session *session) handle(line string) {
|
||||
|
||||
session.mutex.Lock()
|
||||
defer session.mutex.Unlock()
|
||||
cmd := parseLine(line)
|
||||
|
||||
// Commands are dispatched to the appropriate handler functions.
|
||||
|
@ -470,7 +471,7 @@ func (session *session) handleAUTH(cmd command) {
|
|||
encodedUsername := ""
|
||||
|
||||
if len(cmd.fields) < 3 {
|
||||
session.reply(334, "VXNlcm5hbWU6")
|
||||
session.reply(334, "VXNlcm5hbWU6") // `Username:`
|
||||
if !session.scanner.Scan() {
|
||||
return
|
||||
}
|
||||
|
@ -486,7 +487,7 @@ func (session *session) handleAUTH(cmd command) {
|
|||
return
|
||||
}
|
||||
|
||||
session.reply(334, "UGFzc3dvcmQ6")
|
||||
session.reply(334, "UGFzc3dvcmQ6") // `Password:`
|
||||
|
||||
if !session.scanner.Scan() {
|
||||
return
|
||||
|
|
5
smtpd.go
5
smtpd.go
|
@ -158,6 +158,8 @@ type session struct {
|
|||
scanner *bufio.Scanner
|
||||
|
||||
tls bool
|
||||
// mutex is used to guard editing peer's Metadata
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
func (srv *Server) newSession(c net.Conn) (s *session) {
|
||||
|
@ -170,11 +172,12 @@ func (srv *Server) newSession(c net.Conn) (s *session) {
|
|||
peer: &Peer{
|
||||
Addr: c.RemoteAddr(),
|
||||
ServerName: srv.Hostname,
|
||||
Meta: make(map[string]interface{}, 0),
|
||||
},
|
||||
}
|
||||
|
||||
// Check if the underlying connection is already TLS.
|
||||
// This will happen if the Listerner provided Serve()
|
||||
// This will happen if the Listener provided Serve()
|
||||
// is from tls.Listen()
|
||||
|
||||
var tlsConn *tls.Conn
|
||||
|
|
Loading…
Add table
Reference in a new issue