Skip to content

Commit

Permalink
Added more ipfs configs
Browse files Browse the repository at this point in the history
However it throws error related to badgerds plugin not loaded initially
  • Loading branch information
ehsan6sha committed Feb 20, 2024
1 parent 34e39f7 commit d57a86d
Show file tree
Hide file tree
Showing 7 changed files with 547 additions and 80 deletions.
52 changes: 33 additions & 19 deletions blox/blox.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,26 @@ func (p *Blox) Start(ctx context.Context) error {
}

// Create an HTTP server instance
p.IPFShttpServer = &http.Server{
Addr: "127.0.0.1:5001",
Handler: p.ServeIpfsRpc(),
}

log.Debug("called wg.Add in blox start")
p.wg.Add(1)
go func() {
log.Debug("called wg.Done in Start blox")
defer p.wg.Done()
defer log.Debug("Start blox go routine is ending")
log.Infow("IPFS RPC server started on address http://127.0.0.1:5001")
if err := p.IPFShttpServer.ListenAndServe(); err != http.ErrServerClosed {
log.Errorw("IPFS RPC server stopped erroneously", "err", err)
} else {
log.Infow("IPFS RPC server stopped")
if p.DefaultIPFShttpServer {
p.IPFShttpServer = &http.Server{
Addr: "127.0.0.1:5001",
Handler: p.ServeIpfsRpc(),
}
}()

log.Debug("called wg.Add in blox start")
p.wg.Add(1)
go func() {
log.Debug("called wg.Done in Start blox")
defer p.wg.Done()
defer log.Debug("Start blox go routine is ending")
log.Infow("IPFS RPC server started on address http://127.0.0.1:5001")
if err := p.IPFShttpServer.ListenAndServe(); err != http.ErrServerClosed {
log.Errorw("IPFS RPC server stopped erroneously", "err", err)
} else {
log.Infow("IPFS RPC server stopped")
}
}()
}

if anErr == nil {
log.Debug("called wg.Add in AnnounceIExistPeriodically")
Expand Down Expand Up @@ -450,6 +452,10 @@ func (p *Blox) Shutdown(ctx context.Context) error {
// Cancel the context to signal all operations to stop
p.cancel()

// Use a separate context for shutdown with a timeout
shutdownCtx, cancelShutdown := context.WithTimeout(context.Background(), 20*time.Second)
defer cancelShutdown()

// Shutdown the various components
if bErr := p.bl.Shutdown(ctx); bErr != nil {
log.Errorw("Error occurred in blockchain shutdown", "bErr", bErr)
Expand Down Expand Up @@ -500,9 +506,17 @@ func (p *Blox) Shutdown(ctx context.Context) error {
// Handle remaining errors after all goroutines have finished
log.Debug("Shutdown done")
return nil
case <-ctx.Done():
err := ctx.Err()
case <-shutdownCtx.Done():
err := shutdownCtx.Err()
log.Infow("Shutdown completed with timeout", "err", err)
}

// Check for errors from shutdownCtx
if err := shutdownCtx.Err(); err == context.DeadlineExceeded {
// Handle the case where shutdown did not complete in time
log.Warn("Shutdown did not complete in the allotted time")
return err
}

return nil
}
46 changes: 27 additions & 19 deletions blox/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,26 @@ type (
Option func(*options) error
PoolNameUpdater func(string) error
options struct {
h host.Host
name string
topicName string
storeDir string
announceInterval time.Duration
ds datastore.Batching
ls *ipld.LinkSystem
authorizer peer.ID
authorizedPeers []peer.ID
exchangeOpts []exchange.Option
relays []string
updatePoolName PoolNameUpdater
pingCount int
maxPingTime int
minSuccessRate int
blockchainEndpoint string
secretsPath string
IPFShttpServer *http.Server
wg *sync.WaitGroup
h host.Host
name string
topicName string
storeDir string
announceInterval time.Duration
ds datastore.Batching
ls *ipld.LinkSystem
authorizer peer.ID
authorizedPeers []peer.ID
exchangeOpts []exchange.Option
relays []string
updatePoolName PoolNameUpdater
pingCount int
maxPingTime int
minSuccessRate int
blockchainEndpoint string
secretsPath string
IPFShttpServer *http.Server
DefaultIPFShttpServer bool
wg *sync.WaitGroup
}
)

Expand Down Expand Up @@ -156,6 +157,13 @@ func WithDatastore(ds datastore.Batching) Option {
}
}

func WithDefaultIPFShttpServer(n bool) Option {
return func(o *options) error {
o.DefaultIPFShttpServer = n
return nil
}
}

func WithLinkSystem(ls *ipld.LinkSystem) Option {
return func(o *options) error {
o.ls = ls
Expand Down
Loading

0 comments on commit d57a86d

Please sign in to comment.