Skip to content
Snippets Groups Projects
Select Git revision
  • 2670a149781d22bc1e56549d7a57374199d35243
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

critical.go

Blame
  • restServer.go 2.40 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2022 Privategrity Corporation                                   /
    //                                                                             /
    // All rights reserved.                                                        /
    ////////////////////////////////////////////////////////////////////////////////
    
    package restlike
    
    import (
    	"gitlab.com/elixxir/client/catalog"
    	"gitlab.com/elixxir/client/single"
    	"gitlab.com/elixxir/crypto/cyclic"
    	"gitlab.com/xx_network/primitives/id"
    )
    
    // RestServer allows for clients to make REST-like requests this client
    type RestServer interface {
    	// RegisterEndpoint allows the association of a Callback with
    	// a specific URI and a variety of different REST Method
    	RegisterEndpoint(path URI, method Method, cb Callback) error
    
    	// UnregisterEndpoint removes the Callback associated with
    	// a specific URI and REST Method
    	UnregisterEndpoint(path URI, method Method) error
    
    	// Close the internal RestServer endpoints and external services
    	Close()
    }
    
    // singleServer implements the RestServer interface using single-use
    type singleServer struct {
    	receptionId *id.ID
    	listener    single.Listener
    	endpoints   *Endpoints
    }
    
    // NewSingleServer builds a RestServer with single-use and
    // the provided arguments, then registers necessary external services
    func NewSingleServer(receptionId *id.ID, privKey *cyclic.Int, net single.ListenCmix, e2eGrp *cyclic.Group) RestServer {
    	newServer := &singleServer{
    		receptionId: receptionId,
    		endpoints:   &Endpoints{endpoints: make(map[URI]map[Method]Callback)},
    	}
    	newServer.listener = single.Listen(catalog.RestLike, receptionId, privKey,
    		net, e2eGrp, &singleReceiver{newServer.endpoints})
    	return newServer
    }
    
    // RegisterEndpoint allows the association of a Callback with
    // a specific URI and a variety of different REST Method
    func (r *singleServer) RegisterEndpoint(path URI, method Method, cb Callback) error {
    	return r.endpoints.Add(path, method, cb)
    }
    
    // UnregisterEndpoint removes the Callback associated with
    // a specific URI and REST Method
    func (r *singleServer) UnregisterEndpoint(path URI, method Method) error {
    	return r.endpoints.Remove(path, method)
    }
    
    // Close the internal RestServer endpoints and external services
    func (r *singleServer) Close() {
    	// Clear all internal endpoints
    	r.endpoints = nil
    	// Destroy external services
    	r.listener.Stop()
    }