func (p *peer) renewSessionForClient(sess *session, dialFunc func() (net.Conn, error), addr string, protoFuncs []ProtoFunc) error {
var conn, dialErr = dialFunc()
if dialErr != nil {
return dialErr
}
if p.tlsConfig != nil {
conn = tls.Client(conn, p.tlsConfig)
}
oldIP := sess.LocalAddr().String()
oldID := sess.ID()
oldConn := sess.getConn()
if oldConn != nil {
oldConn.Close()
}
sess.socket.Reset(conn, protoFuncs...)
if oldIP == oldID {
sess.socket.SetID(sess.LocalAddr().String())
} else {
sess.socket.SetID(oldID)
}
atomic.StoreInt32(&sess.status, statusOk) //将状态修改放在plugin之前
if rerr := p.pluginContainer.postDial(sess); rerr != nil {
sess.Close()
return rerr.ToError()
}
// atomic.StoreInt32(&sess.status, statusOk)
AnywayGo(sess.startReadAndHandle)
p.sessHub.Set(sess)
return nil
}