-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup message handling code (#136)
* Remove the "Type" field from Message models * Message handlers accept concrete types * Fix flag handling + update integration tests * Filter messages depending on where they come from (publish vs direct)
- Loading branch information
Showing
47 changed files
with
444 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
cmd/node/node | ||
cmd/node/.b7s_* | ||
cmd/node/*.yaml | ||
|
||
cmd/keygen/keygen | ||
cmd/keyforge/keyforge | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
package request | ||
|
||
import ( | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"encoding/json" | ||
|
||
"github.com/blocklessnetwork/b7s/models/blockless" | ||
) | ||
|
||
var _ (json.Marshaler) = (*DisbandCluster)(nil) | ||
|
||
// DisbandCluster describes the `MessageDisbandCluster` request payload. | ||
// It is sent after head node receives the leaders execution response. | ||
type DisbandCluster struct { | ||
Type string `json:"type,omitempty"` | ||
From peer.ID `json:"from,omitempty"` | ||
RequestID string `json:"request_id,omitempty"` | ||
RequestID string `json:"request_id,omitempty"` | ||
} | ||
|
||
func (DisbandCluster) Type() string { return blockless.MessageDisbandCluster } | ||
|
||
func (d DisbandCluster) MarshalJSON() ([]byte, error) { | ||
type Alias DisbandCluster | ||
rec := struct { | ||
Alias | ||
Type string `json:"type"` | ||
}{ | ||
Alias: Alias(d), | ||
Type: d.Type(), | ||
} | ||
return json.Marshal(rec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
package request | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
|
||
"github.com/blocklessnetwork/b7s/models/blockless" | ||
"github.com/blocklessnetwork/b7s/models/execute" | ||
) | ||
|
||
var _ (json.Marshaler) = (*Execute)(nil) | ||
|
||
// Execute describes the `MessageExecute` request payload. | ||
type Execute struct { | ||
Type string `json:"type,omitempty"` | ||
From peer.ID `json:"from,omitempty"` | ||
Code string `json:"code,omitempty"` | ||
Topic string `json:"topic,omitempty"` | ||
|
||
execute.Request // execute request is embedded. | ||
|
||
// RequestID may be set initially, if the execution request is relayed via roll-call. | ||
RequestID string `json:"request_id,omitempty"` | ||
Topic string `json:"topic,omitempty"` | ||
RequestID string `json:"request_id,omitempty"` // RequestID may be set initially, if the execution request is relayed via roll-call. | ||
Timestamp time.Time `json:"timestamp,omitempty"` // Execution request timestamp is a factor for PBFT. | ||
} | ||
|
||
func (Execute) Type() string { return blockless.MessageExecute } | ||
|
||
// Execution request timestamp is a factor for PBFT. | ||
Timestamp time.Time `json:"timestamp,omitempty"` | ||
func (e Execute) MarshalJSON() ([]byte, error) { | ||
type Alias Execute | ||
rec := struct { | ||
Alias | ||
Type string `json:"type"` | ||
}{ | ||
Alias: Alias(e), | ||
Type: e.Type(), | ||
} | ||
return json.Marshal(rec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
package request | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
|
||
"github.com/blocklessnetwork/b7s/consensus" | ||
"github.com/blocklessnetwork/b7s/models/blockless" | ||
) | ||
|
||
var _ (json.Marshaler) = (*FormCluster)(nil) | ||
|
||
// FormCluster describes the `MessageFormCluster` request payload. | ||
// It is sent on clustered execution of a request. | ||
type FormCluster struct { | ||
Type string `json:"type,omitempty"` | ||
From peer.ID `json:"from,omitempty"` | ||
RequestID string `json:"request_id,omitempty"` | ||
Peers []peer.ID `json:"peers,omitempty"` | ||
Consensus consensus.Type `json:"consensus,omitempty"` | ||
} | ||
|
||
func (FormCluster) Type() string { return blockless.MessageFormCluster } | ||
|
||
func (f FormCluster) MarshalJSON() ([]byte, error) { | ||
type Alias FormCluster | ||
rec := struct { | ||
Alias | ||
Type string `json:"type"` | ||
}{ | ||
Alias: Alias(f), | ||
Type: f.Type(), | ||
} | ||
return json.Marshal(rec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
package request | ||
|
||
import ( | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"encoding/json" | ||
|
||
"github.com/blocklessnetwork/b7s/models/blockless" | ||
) | ||
|
||
var _ (json.Marshaler) = (*InstallFunction)(nil) | ||
|
||
// InstallFunction describes the `MessageInstallFunction` request payload. | ||
type InstallFunction struct { | ||
Type string `json:"type,omitempty"` | ||
From peer.ID `json:"from,omitempty"` | ||
ManifestURL string `json:"manifest_url,omitempty"` | ||
CID string `json:"cid,omitempty"` | ||
ManifestURL string `json:"manifest_url,omitempty"` | ||
CID string `json:"cid,omitempty"` | ||
} | ||
|
||
func (InstallFunction) Type() string { return blockless.MessageInstallFunction } | ||
|
||
func (f InstallFunction) MarshalJSON() ([]byte, error) { | ||
type Alias InstallFunction | ||
rec := struct { | ||
Alias | ||
Type string `json:"type"` | ||
}{ | ||
Alias: Alias(f), | ||
Type: f.Type(), | ||
} | ||
return json.Marshal(rec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
package request | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
|
||
"github.com/blocklessnetwork/b7s/consensus" | ||
"github.com/blocklessnetwork/b7s/models/blockless" | ||
"github.com/blocklessnetwork/b7s/models/execute" | ||
) | ||
|
||
var _ (json.Marshaler) = (*RollCall)(nil) | ||
|
||
// RollCall describes the `MessageRollCall` message payload. | ||
type RollCall struct { | ||
From peer.ID `json:"from,omitempty"` | ||
Type string `json:"type,omitempty"` | ||
Origin peer.ID `json:"origin,omitempty"` // Origin is the peer that initiated the roll call. | ||
FunctionID string `json:"function_id,omitempty"` | ||
RequestID string `json:"request_id,omitempty"` | ||
Consensus consensus.Type `json:"consensus"` | ||
Attributes *execute.Attributes `json:"attributes,omitempty"` | ||
} | ||
|
||
func (RollCall) Type() string { return blockless.MessageRollCall } | ||
|
||
func (r RollCall) MarshalJSON() ([]byte, error) { | ||
type Alias RollCall | ||
rec := struct { | ||
Alias | ||
Type string `json:"type"` | ||
}{ | ||
Alias: Alias(r), | ||
Type: r.Type(), | ||
} | ||
return json.Marshal(rec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.