Skip to content

Commit

Permalink
fix: mutex for send, validate session exists in passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
dehydr8 committed Jan 23, 2024
1 parent 4cef4e1 commit 36dd90b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions protocol/aes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"io"
"net/http"
"sync"
"time"

"github.com/dehydr8/kasa-go/logger"
Expand All @@ -35,6 +36,8 @@ type AesTransport struct {
httpClient *http.Client

commonHeaders map[string]string

sendLock sync.Mutex
}

type AesProtoBaseRequest struct {
Expand Down Expand Up @@ -116,6 +119,9 @@ func NewAesTransport(key *rsa.PrivateKey, config *model.DeviceConfig) (*AesTrans
}

func (t *AesTransport) Send(request, response interface{}) error {
t.sendLock.Lock()
defer t.sendLock.Unlock()

if !t.handshakeDone || t.handshakeExpired() {
err := t.handshake()

Expand Down Expand Up @@ -272,6 +278,9 @@ func (t *AesTransport) login() error {
}

func (t *AesTransport) securePassthrough(request interface{}, response interface{}) error {
if t.session == nil {
return fmt.Errorf("session not initialized")
}

url := fmt.Sprintf("http://%s/app", t.config.Address)
if t.loginToken != "" {
Expand Down

0 comments on commit 36dd90b

Please sign in to comment.