mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
@@ -115,6 +115,7 @@ type exportMap struct {
|
||||
services map[string]*exportAuth
|
||||
}
|
||||
|
||||
// NewAccount creates a new unlimited account with the given name.
|
||||
func NewAccount(name string) *Account {
|
||||
a := &Account{
|
||||
Name: name,
|
||||
@@ -135,7 +136,7 @@ func (a *Account) shallowCopy() *Account {
|
||||
return na
|
||||
}
|
||||
|
||||
// NumClients returns active number of clients for this account for
|
||||
// NumConnections returns active number of clients for this account for
|
||||
// all known servers.
|
||||
func (a *Account) NumConnections() int {
|
||||
a.mu.RLock()
|
||||
@@ -144,7 +145,7 @@ func (a *Account) NumConnections() int {
|
||||
return nc
|
||||
}
|
||||
|
||||
// NumLocalClients returns active number of clients for this account
|
||||
// NumLocalConnections returns active number of clients for this account
|
||||
// on this server.
|
||||
func (a *Account) NumLocalConnections() int {
|
||||
a.mu.RLock()
|
||||
@@ -186,7 +187,7 @@ func (a *Account) MaxActiveConnections() int {
|
||||
return mconns
|
||||
}
|
||||
|
||||
// MaxTotalLeafNodesReached() returns if we have reached our limit for number of leafnodes.
|
||||
// MaxTotalLeafNodesReached returns if we have reached our limit for number of leafnodes.
|
||||
func (a *Account) MaxTotalLeafNodesReached() bool {
|
||||
a.mu.RLock()
|
||||
mtc := a.maxTotalLeafNodesReached()
|
||||
@@ -219,7 +220,7 @@ func (a *Account) NumRemoteLeafNodes() int {
|
||||
return nrn
|
||||
}
|
||||
|
||||
// MaxActiveLeafnodes return the set limit for the account system
|
||||
// MaxActiveLeafNodes return the set limit for the account system
|
||||
// wide for total number of leavenode connections.
|
||||
// NOTE: these are tracked separately.
|
||||
func (a *Account) MaxActiveLeafNodes() int {
|
||||
@@ -333,6 +334,7 @@ func (a *Account) numServiceRoutes() int {
|
||||
return len(a.imports.services)
|
||||
}
|
||||
|
||||
// AddServiceImportWithClaim will add in the service import via the jwt claim.
|
||||
func (a *Account) AddServiceImportWithClaim(destination *Account, from, to string, imClaim *jwt.Import) error {
|
||||
if destination == nil {
|
||||
return ErrMissingAccount
|
||||
@@ -1150,6 +1152,7 @@ type AccountResolver interface {
|
||||
Store(name, jwt string) error
|
||||
}
|
||||
|
||||
// MemAccResolver is a memory only resolver.
|
||||
// Mostly for testing.
|
||||
type MemAccResolver struct {
|
||||
sm sync.Map
|
||||
|
||||
@@ -1903,9 +1903,7 @@ func (c *client) processUnsub(arg []byte) error {
|
||||
c.in.subs++
|
||||
|
||||
var sub *subscription
|
||||
|
||||
unsub := false
|
||||
ok := false
|
||||
var ok, unsub bool
|
||||
|
||||
c.mu.Lock()
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ type accNumConnsReq struct {
|
||||
Account string `json:"acc"`
|
||||
}
|
||||
|
||||
// ServerInfo identifies remote servers.
|
||||
type ServerInfo struct {
|
||||
Host string `json:"host"`
|
||||
ID string `json:"id"`
|
||||
@@ -126,7 +127,7 @@ type ClientInfo struct {
|
||||
Stop *time.Time `json:"stop,omitempty"`
|
||||
}
|
||||
|
||||
// Various statistics we will periodically send out.
|
||||
// ServerStats hold various statistics that we will periodically send out.
|
||||
type ServerStats struct {
|
||||
Start time.Time `json:"start"`
|
||||
Mem int64 `json:"mem"`
|
||||
@@ -143,6 +144,7 @@ type ServerStats struct {
|
||||
Gateways []*GatewayStat `json:"gateways,omitempty"`
|
||||
}
|
||||
|
||||
// RouteStat holds route statistics.
|
||||
type RouteStat struct {
|
||||
ID uint64 `json:"rid"`
|
||||
Sent DataStats `json:"sent"`
|
||||
@@ -150,6 +152,7 @@ type RouteStat struct {
|
||||
Pending int `json:"pending"`
|
||||
}
|
||||
|
||||
// GatewayStat holds gateway statistics.
|
||||
type GatewayStat struct {
|
||||
ID uint64 `json:"gwid"`
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -77,8 +77,11 @@ type ConnzOptions struct {
|
||||
type ConnState int
|
||||
|
||||
const (
|
||||
// ConnOpen filters on open clients.
|
||||
ConnOpen = ConnState(iota)
|
||||
// ConnClosed filters on closed clients.
|
||||
ConnClosed
|
||||
// ConnAll returns all clients.
|
||||
ConnAll
|
||||
)
|
||||
|
||||
|
||||
@@ -17,11 +17,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Represents a connection info list. We use pointers since it will be sorted.
|
||||
// ConnInfos represents a connection info list. We use pointers since it will be sorted.
|
||||
type ConnInfos []*ConnInfo
|
||||
|
||||
// For sorting
|
||||
func (cl ConnInfos) Len() int { return len(cl) }
|
||||
// Len returns length for sorting.
|
||||
func (cl ConnInfos) Len() int { return len(cl) }
|
||||
|
||||
// Swap will sawap the elements.
|
||||
func (cl ConnInfos) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] }
|
||||
|
||||
// SortOpt is a helper type to sort clients
|
||||
|
||||
@@ -86,6 +86,7 @@ func periodic() {
|
||||
time.AfterFunc(1*time.Second, periodic)
|
||||
}
|
||||
|
||||
// ProcUsage returns CPU usage
|
||||
func ProcUsage(pcpu *float64, rss, vss *int64) error {
|
||||
contents, err := ioutil.ReadFile(procStatFile)
|
||||
if err != nil {
|
||||
|
||||
@@ -177,8 +177,8 @@ type stats struct {
|
||||
slowConsumers int64
|
||||
}
|
||||
|
||||
// DEPRECATED: Use NewServer(opts)
|
||||
// New will setup a new server struct after parsing the options.
|
||||
// DEPRECATED: Use NewServer(opts)
|
||||
func New(opts *Options) *Server {
|
||||
s, _ := NewServer(opts)
|
||||
return s
|
||||
@@ -858,22 +858,23 @@ func (s *Server) fetchAccountClaims(name string) (*jwt.AccountClaims, string, er
|
||||
|
||||
// verifyAccountClaims will decode and validate any account claims.
|
||||
func (s *Server) verifyAccountClaims(claimJWT string) (*jwt.AccountClaims, string, error) {
|
||||
if accClaims, err := jwt.DecodeAccountClaims(claimJWT); err != nil {
|
||||
accClaims, err := jwt.DecodeAccountClaims(claimJWT)
|
||||
if err != nil {
|
||||
return nil, _EMPTY_, err
|
||||
} else {
|
||||
vr := jwt.CreateValidationResults()
|
||||
accClaims.Validate(vr)
|
||||
if vr.IsBlocking(true) {
|
||||
return nil, _EMPTY_, ErrAccountValidation
|
||||
}
|
||||
return accClaims, claimJWT, nil
|
||||
}
|
||||
vr := jwt.CreateValidationResults()
|
||||
accClaims.Validate(vr)
|
||||
if vr.IsBlocking(true) {
|
||||
return nil, _EMPTY_, ErrAccountValidation
|
||||
}
|
||||
return accClaims, claimJWT, nil
|
||||
}
|
||||
|
||||
// This will fetch an account from a resolver if defined.
|
||||
// Lock should be held upon entry.
|
||||
func (s *Server) fetchAccount(name string) (*Account, error) {
|
||||
if accClaims, claimJWT, err := s.fetchAccountClaims(name); accClaims != nil {
|
||||
accClaims, claimJWT, err := s.fetchAccountClaims(name)
|
||||
if accClaims != nil {
|
||||
// We have released the lock during the low level fetch.
|
||||
// Now that we are back under lock, check again if account
|
||||
// is in the map or not. If it is, simply return it.
|
||||
@@ -892,9 +893,8 @@ func (s *Server) fetchAccount(name string) (*Account, error) {
|
||||
acc.claimJWT = claimJWT
|
||||
s.registerAccount(acc)
|
||||
return acc, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Start up the server, this will block.
|
||||
@@ -1789,6 +1789,7 @@ func (s *Server) getClient(cid uint64) *client {
|
||||
return s.clients[cid]
|
||||
}
|
||||
|
||||
// GetLeafNode returns the leafnode associated with the cid.
|
||||
func (s *Server) GetLeafNode(cid uint64) *client {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
@@ -1001,7 +1001,7 @@ func (s *Sublist) localSubs(subs *[]*subscription) {
|
||||
s.RUnlock()
|
||||
}
|
||||
|
||||
// Used to collect all subscriptions.
|
||||
// All is used to collect all subscriptions.
|
||||
func (s *Sublist) All(subs *[]*subscription) {
|
||||
s.RLock()
|
||||
s.collectAllSubs(s.root, subs)
|
||||
|
||||
Reference in New Issue
Block a user