Revert "feat(structs#Session): made sessionID and sequence fields public"

This reverts commit 4390b565fa.
This commit is contained in:
nitroflap 2022-02-27 18:11:50 +03:00
parent 4390b565fa
commit 5056d53d17
4 changed files with 12 additions and 12 deletions

View file

@ -41,7 +41,7 @@ func New(token string) (s *Session, err error) {
MaxRestRetries: 3,
Client: &http.Client{Timeout: (20 * time.Second)},
UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
Sequence: new(int64),
sequence: new(int64),
LastHeartbeatAck: time.Now().UTC(),
}

View file

@ -243,5 +243,5 @@ func (s *Session) onInterface(i interface{}) {
func (s *Session) onReady(r *Ready) {
// Store the SessionID within the Session struct.
s.SessionID = r.SessionID
s.sessionID = r.SessionID
}

View file

@ -115,14 +115,14 @@ type Session struct {
// When nil, the session is not listening.
listening chan interface{}
// Sequence tracks the current gateway api websocket sequence number
Sequence *int64
// sequence tracks the current gateway api websocket sequence number
sequence *int64
// stores sessions current Discord Gateway
gateway string
// SessionID stores session ID of current Gateway connection
SessionID string
// stores session ID of current Gateway connection
sessionID string
// used to make sure gateway websocket writes do not happen concurrently
wsMutex sync.Mutex

View file

@ -123,8 +123,8 @@ func (s *Session) Open() error {
// Now we send either an Op 2 Identity if this is a brand new
// connection or Op 6 Resume if we are resuming an existing connection.
sequence := atomic.LoadInt64(s.Sequence)
if s.SessionID == "" && sequence == 0 {
sequence := atomic.LoadInt64(s.sequence)
if s.sessionID == "" && sequence == 0 {
// Send Op 2 Identity Packet
err = s.identify()
@ -139,7 +139,7 @@ func (s *Session) Open() error {
p := resumePacket{}
p.Op = 6
p.Data.Token = s.Token
p.Data.SessionID = s.SessionID
p.Data.SessionID = s.sessionID
p.Data.Sequence = sequence
s.log(LogInformational, "sending resume packet to gateway")
@ -291,7 +291,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
s.RLock()
last := s.LastHeartbeatAck
s.RUnlock()
sequence := atomic.LoadInt64(s.Sequence)
sequence := atomic.LoadInt64(s.sequence)
s.log(LogDebug, "sending gateway websocket heartbeat seq %d", sequence)
s.wsMutex.Lock()
s.LastHeartbeatSent = time.Now().UTC()
@ -518,7 +518,7 @@ func (s *Session) onEvent(messageType int, message []byte) (*Event, error) {
if e.Operation == 1 {
s.log(LogInformational, "sending heartbeat in response to Op1")
s.wsMutex.Lock()
err = s.wsConn.WriteJSON(heartbeatOp{1, atomic.LoadInt64(s.Sequence)})
err = s.wsConn.WriteJSON(heartbeatOp{1, atomic.LoadInt64(s.sequence)})
s.wsMutex.Unlock()
if err != nil {
s.log(LogError, "error sending heartbeat in response to Op1")
@ -574,7 +574,7 @@ func (s *Session) onEvent(messageType int, message []byte) (*Event, error) {
}
// Store the message sequence
atomic.StoreInt64(s.Sequence, e.Sequence)
atomic.StoreInt64(s.sequence, e.Sequence)
// Map event to registered event handlers and pass it along to any registered handlers.
if eh, ok := registeredInterfaceProviders[e.Type]; ok {