-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
2,545 additions
and
1,979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,6 @@ _testmain.go | |
persistence/examples/bolt/test.db | ||
examples/tcp/persist.db | ||
coverage.txt | ||
vendor | ||
vendor | ||
|
||
persist.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package auth | ||
|
||
type Simple interface { | ||
Password(u, p string) Status | ||
} | ||
|
||
type Anonymous interface { | ||
Is() Status | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package clients | ||
|
||
import ( | ||
"sync" | ||
"sync/atomic" | ||
|
||
"github.com/VolantMQ/volantmq/subscriber" | ||
) | ||
|
||
type container struct { | ||
lock sync.Mutex | ||
ses atomic.Value | ||
expiry atomic.Value | ||
sub *subscriber.Type | ||
} | ||
|
||
func (s *container) acquire() { | ||
s.lock.Lock() | ||
} | ||
|
||
func (s *container) release() { | ||
s.lock.Unlock() | ||
} | ||
|
||
func (s *container) session() *session { | ||
return s.ses.Load().(*session) | ||
} | ||
|
||
func (s *container) swap(w *container) *container { | ||
s.ses = w.ses | ||
|
||
ses := s.ses.Load().(*session) | ||
ses.idLock = &s.lock | ||
|
||
return s | ||
} | ||
|
||
func (s *container) subscriber(cleanStart bool, c subscriber.Config) (*subscriber.Type, bool) { | ||
if cleanStart && s.sub != nil { | ||
s.sub.Offline(true) | ||
s.sub = nil | ||
} | ||
|
||
if s.sub == nil { | ||
s.sub = subscriber.New(c) | ||
cleanStart = true | ||
} else { | ||
cleanStart = false | ||
} | ||
|
||
return s.sub, !cleanStart | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package clients | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/VolantMQ/volantmq/packet" | ||
"github.com/VolantMQ/volantmq/types" | ||
) | ||
|
||
type expiryEvent interface { | ||
sessionTimer(string, bool) | ||
} | ||
|
||
type expiryConfig struct { | ||
expiryEvent | ||
id string | ||
createdAt time.Time | ||
messenger types.TopicMessenger | ||
will *packet.Publish | ||
expireIn *uint32 | ||
willDelay uint32 | ||
} | ||
|
||
type expiry struct { | ||
expiryConfig | ||
expiringSince time.Time | ||
timerLock sync.Mutex | ||
timer *time.Timer | ||
} | ||
|
||
func newExpiry(c expiryConfig) *expiry { | ||
return &expiry{ | ||
expiryConfig: c, | ||
} | ||
} | ||
|
||
func (s *expiry) start() { | ||
var timerPeriod uint32 | ||
|
||
// if meet will requirements point that | ||
if s.will != nil && s.willDelay > 0 { | ||
timerPeriod = s.willDelay | ||
} else { | ||
s.will = nil | ||
} | ||
|
||
if s.expireIn != nil { | ||
// if will delay is set before and value less than expiration | ||
// then timer should fire 2 times | ||
if (timerPeriod > 0) && (timerPeriod < *s.expireIn) { | ||
*s.expireIn = *s.expireIn - timerPeriod | ||
} else { | ||
timerPeriod = *s.expireIn | ||
*s.expireIn = 0 | ||
} | ||
} | ||
|
||
s.expiringSince = time.Now() | ||
s.timer = time.NewTimer(time.Duration(timerPeriod) * time.Second) | ||
} | ||
|
||
func (s *expiry) cancel() { | ||
if !s.timer.Stop() { | ||
s.timerLock.Lock() | ||
s.timerLock.Unlock() // nolint: megacheck | ||
} | ||
} | ||
|
||
func (s *expiry) timerCallback() { | ||
defer s.timerLock.Unlock() | ||
s.timerLock.Lock() | ||
|
||
// 1. check for will message available | ||
if s.will != nil { | ||
// publish if exists and wipe state | ||
s.messenger.Publish(s.will) // nolint: errcheck | ||
s.will = nil | ||
s.willDelay = 0 | ||
} | ||
|
||
if s.expireIn == nil { | ||
// 2.a session has processed delayed will and there is nothing to do | ||
// completely shutdown the session | ||
s.sessionTimer(s.id, false) | ||
} else if *s.expireIn == 0 { | ||
// session has expired. WIPE IT | ||
//if s.subscriber != nil { | ||
// s.shutdownSubscriber(s.subscriber) | ||
//} | ||
s.sessionTimer(s.id, true) | ||
} else { | ||
// restart timer and wait again | ||
val := *s.expireIn | ||
// clear value pointed by expireIn so when next fire comes we signal session is expired | ||
*s.expireIn = 0 | ||
s.timer.Reset(time.Duration(val) * time.Second) | ||
} | ||
} |
Oops, something went wrong.