Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/300/allow ignore private transaction #462

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions private/constellation/constellation.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package constellation

import (
"errors"
"fmt"
"github.com/patrickmn/go-cache"
"os"
"path/filepath"
"strings"
"time"

"github.com/patrickmn/go-cache"
)

type Constellation struct {
node *Client
c *cache.Cache
node *Client
c *cache.Cache
isConstellationNotInUse bool
}

var (
ErrConstellationIsntInit = errors.New("Constellation not in use")
)

func (g *Constellation) Send(data []byte, from string, to []string) (out []byte, err error) {
if g.isConstellationNotInUse {
return nil, ErrConstellationIsntInit
}
out, err = g.node.SendPayload(data, from, to)
if err != nil {
return nil, err
Expand All @@ -23,6 +34,9 @@ func (g *Constellation) Send(data []byte, from string, to []string) (out []byte,
}

func (g *Constellation) Receive(data []byte) ([]byte, error) {
if g.isConstellationNotInUse {
return nil, nil
}
if len(data) == 0 {
return data, nil
}
Expand All @@ -47,7 +61,7 @@ func New(path string) (*Constellation, error) {
}
// We accept either the socket or a configuration file that points to
// a socket.
isSocket := info.Mode() & os.ModeSocket != 0
isSocket := info.Mode()&os.ModeSocket != 0
if !isSocket {
cfg, err := LoadConfig(path)
if err != nil {
Expand All @@ -66,10 +80,18 @@ func New(path string) (*Constellation, error) {
return &Constellation{
node: n,
c: cache.New(5*time.Minute, 5*time.Minute),
isConstellationNotInUse: false,
}, nil
}

func MustNew(path string) *Constellation {
if strings.EqualFold(path, "ignore") {
return &Constellation{
node: nil,
c: nil,
isConstellationNotInUse: true,
}
}
g, err := New(path)
if err != nil {
panic(fmt.Sprintf("MustNew: Failed to connect to Constellation (%s): %v", path, err))
Expand Down