Working authenticated connection

This commit is contained in:
2023-09-18 20:58:15 -05:00
parent 11b176dcbc
commit c89756630f
10 changed files with 126 additions and 62 deletions

View File

@ -2,10 +2,10 @@ package dispatcher
import (
"fmt"
"github.com/thesyncim/faye/internal/store"
"github.com/thesyncim/faye/message"
"github.com/thesyncim/faye/subscription"
"github.com/thesyncim/faye/transport"
"github.com/thesyncim/fayec/internal/store"
"github.com/thesyncim/fayec/message"
"github.com/thesyncim/fayec/subscription"
"github.com/thesyncim/fayec/transport"
"log"
"strconv"
"sync"
@ -46,7 +46,7 @@ func NewDispatcher(endpoint string, tOpts transport.Options, ext message.Extensi
}
}
//todo allow multiple transports
// todo allow multiple transports
func (d *Dispatcher) Connect() error {
var err error
if err = d.transport.Init(d.endpoint, &d.transportOpts); err != nil {
@ -166,7 +166,7 @@ func (d *Dispatcher) nextMsgID() string {
return strconv.Itoa(int(atomic.AddUint64(d.msgID, 1)))
}
//sendMessage send applies the out extensions and sends a message throught the transport
// sendMessage send applies the out extensions and sends a message throught the transport
func (d *Dispatcher) sendMessage(m *message.Message) error {
d.extensions.ApplyOutExtensions(m)
return d.transport.SendMessage(m)
@ -180,6 +180,7 @@ func (d *Dispatcher) Subscribe(channel string) (*subscription.Subscription, erro
Subscription: channel,
Id: id,
}
d.extensions.ApplyOutExtensions(m)
if err := d.transport.SendMessage(m); err != nil {
return nil, err

View File

@ -1,7 +1,7 @@
package store
import (
"github.com/thesyncim/faye/subscription"
"github.com/thesyncim/fayec/subscription"
"sync"
)
@ -26,8 +26,8 @@ func (s *SubscriptionsStore) Add(sub *subscription.Subscription) {
s.mutex.Unlock()
}
//Match returns the subscriptions that match with the specified channel name
//Wildcard subscriptions are matched
// Match returns the subscriptions that match with the specified channel name
// Wildcard subscriptions are matched
func (s *SubscriptionsStore) Match(channel string) []*subscription.Subscription {
var (
matches []*subscription.Subscription
@ -70,7 +70,7 @@ end:
s.mutex.Unlock()
}
//RemoveAll removel all subscriptions and close all channels
// RemoveAll removel all subscriptions and close all channels
func (s *SubscriptionsStore) RemoveAll() {
s.mutex.Lock()
for i := range s.subs {
@ -84,7 +84,7 @@ func (s *SubscriptionsStore) RemoveAll() {
s.mutex.Unlock()
}
//Count return the number of subscriptions associated with the specified channel
// Count return the number of subscriptions associated with the specified channel
func (s *SubscriptionsStore) Count(channel string) int {
return len(s.Match(channel))
}

View File

@ -7,8 +7,8 @@ import (
)
var (
wildcardSubscription, _ = subscription.NewSubscription("a", "/wildcard/*", nil, nil, nil)
simpleSubscription, _ = subscription.NewSubscription("b", "/foo/bar", nil, nil, nil)
wildcardSubscription, _ = subscription.NewSubscription("a", nil, nil)
simpleSubscription, _ = subscription.NewSubscription("b", nil, nil)
)
func TestStore_Add(t *testing.T) {