-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-5868] Specify collection interface
This generic collection interface is implemented by different kinds of collection types. The collection's access policy interface is consumed by gossip to govern access to private read-write sets. The collection store acts as a collection factory and serves collection objects based on collection criteria. The nop-collection is an implementation of both interfaces, i.e. a collection type, that allows all organizations to pull a private read-write set and a collection store that just returns an instance of this collection type. Change-Id: I9a589c1609a719a593918896623586583568a262 Signed-off-by: Matthias Neugschwandtner <eug@zurich.ibm.com>
- Loading branch information
Matthias Neugschwandtner
committed
Sep 28, 2017
1 parent
6cc7444
commit 4a3c528
Showing
10 changed files
with
306 additions
and
263 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package privdata | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/protos/common" | ||
) | ||
|
||
// Collection defines a common interface for collections | ||
type Collection interface { | ||
// SetTxContext configures the tx-specific ephemeral collection info, such | ||
// as txid, nonce, creator -- for future use | ||
// SetTxContext(parameters ...interface{}) | ||
|
||
// GetCollectionID returns this collection's ID | ||
GetCollectionID() string | ||
|
||
// GetEndorsementPolicy returns the endorsement policy for validation -- for | ||
// future use | ||
// GetEndorsementPolicy() string | ||
|
||
// GetMemberOrgs returns the collection's members as MSP IDs. This serves as | ||
// a human-readable way of quickly identifying who is part of a collection. | ||
GetMemberOrgs() []string | ||
} | ||
|
||
// CollectionAccess encapsulates functions for the access policy of a collection | ||
type CollectionAccessPolicy interface { | ||
// GetAccessFilter returns a member filter function for a collection | ||
GetAccessFilter() Filter | ||
|
||
// RequiredExternalPeerCount returns the minimum number of external peers | ||
// required to hold private data | ||
RequiredExternalPeerCount() int | ||
|
||
// RequiredExternalPeerCount returns the minimum number of internal peers | ||
// required to hold private data | ||
RequiredInternalPeerCount() int | ||
} | ||
|
||
// Filter defines a rule that filters peers according to data signed by them. | ||
// The Identity in the SignedData is a SerializedIdentity of a peer. | ||
// The Data is a message the peer signed, and the Signature is the corresponding | ||
// Signature on that Data. | ||
// Returns: True, if the policy holds for the given signed data. | ||
// False otherwise | ||
type Filter func(common.SignedData) bool | ||
|
||
// CollectionStore retrieves stored collections based on the collection's | ||
// properties. It works as a collection object factory and takes care of | ||
// returning a collection object of an appropriate collection type. | ||
type CollectionStore interface { | ||
// GetCollection retrieves the collection in the following way: | ||
// If the TxID exists in the ledger, the collection that is returned has the | ||
// latest configuration that was committed into the ledger before this txID | ||
// was committed. | ||
// Else - it's the latest configuration for the collection. | ||
GetCollection(common.CollectionCriteria) Collection | ||
|
||
// GetCollectionAccessPolicy retrieves a collection's access policy | ||
GetCollectionAccessPolicy(common.CollectionCriteria) CollectionAccessPolicy | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package privdata | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/protos/common" | ||
) | ||
|
||
// NopCollection implements an allow-all collection which all orgs are a member of | ||
type NopCollection struct { | ||
} | ||
|
||
func (nc *NopCollection) GetCollectionID() string { | ||
return "" | ||
} | ||
|
||
func (nc *NopCollection) GetEndorsementPolicy() string { | ||
return "" | ||
} | ||
|
||
func (nc *NopCollection) GetMemberOrgs() []string { | ||
return nil | ||
} | ||
|
||
func (nc *NopCollection) RequiredExternalPeerCount() int { | ||
return 0 | ||
} | ||
|
||
func (nc *NopCollection) RequiredInternalPeerCount() int { | ||
return 0 | ||
} | ||
|
||
func (nc *NopCollection) GetAccessFilter() Filter { | ||
// return true for all | ||
return func(common.SignedData) bool { | ||
return true | ||
} | ||
} | ||
|
||
type NopCollectionStore struct { | ||
} | ||
|
||
func (*NopCollectionStore) GetCollection(common.CollectionCriteria) Collection { | ||
return &NopCollection{} | ||
} | ||
|
||
func (*NopCollectionStore) GetCollectionAccessPolicy(common.CollectionCriteria) CollectionAccessPolicy { | ||
return &NopCollection{} | ||
} |
This file was deleted.
Oops, something went wrong.
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.