This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add RPC call Metadata requesting first sector ID
This is second attempt of #2321 The whole list of IDs can be expensive for a host to provide for free, but the first sector ID is constant size and cheap. At the same time it opens doors for stateless clients, i.e. recovering everything from seed only. (IDs of other sectors can be stored in the first sector.)
- Loading branch information
Boris Nagaev
committed
Dec 26, 2017
1 parent
4a1659e
commit 75c8e7a
Showing
7 changed files
with
167 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package host | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/NebulousLabs/Sia/encoding" | ||
) | ||
|
||
// managedRPCMetadata accepts a request to get list of sector ids. | ||
func (h *Host) managedRPCMetadata(conn net.Conn) error { | ||
// Perform the file contract revision exchange, giving the renter the most | ||
// recent file contract revision and getting the storage obligation that | ||
// will be used to get sector ids. | ||
_, so, err := h.managedRPCRecentRevision(conn) | ||
if err != nil { | ||
return extendErr("RPCRecentRevision failed: ", err) | ||
} | ||
// The storage obligation is received with a lock on it. Defer a call to | ||
// unlock the storage obligation. | ||
defer func() { | ||
h.managedUnlockStorageObligation(so.id()) | ||
}() | ||
if len(so.SectorRoots) == 0 { | ||
return nil | ||
} | ||
// Write roots of all sectors. | ||
err = encoding.WriteObject(conn, so.SectorRoots[0]) | ||
if err != nil { | ||
return extendErr("cound not write sectors: ", ErrorConnection(err.Error())) | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package proto | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"time" | ||
|
||
"github.com/NebulousLabs/Sia/crypto" | ||
"github.com/NebulousLabs/Sia/encoding" | ||
"github.com/NebulousLabs/Sia/modules" | ||
"github.com/NebulousLabs/Sia/types" | ||
) | ||
|
||
// GetMetadata downloads ID of the first sector from the host. | ||
func GetMetadata(host modules.HostDBEntry, fcid types.FileContractID, sk crypto.SecretKey, windowStart types.BlockHeight, cancel <-chan struct{}) (lastRevision types.FileContractRevision, id crypto.Hash, err error) { | ||
conn, err := (&net.Dialer{ | ||
Cancel: cancel, | ||
Timeout: 15 * time.Second, | ||
}).Dial("tcp", string(host.NetAddress)) | ||
if err != nil { | ||
return types.FileContractRevision{}, crypto.Hash{}, err | ||
} | ||
defer conn.Close() | ||
// allot 2 minutes for RPC request + revision exchange | ||
extendDeadline(conn, modules.NegotiateMetadataTime) | ||
if err = encoding.WriteObject(conn, modules.RPCMetadata); err != nil { | ||
err = errors.New("couldn't initiate RPC: " + err.Error()) | ||
return | ||
} | ||
lastRevision, err = getRecentRevision(conn, fcid, sk, windowStart, host.Version) | ||
if err != nil { | ||
return | ||
} | ||
if lastRevision.NewFileSize != 0 { | ||
if err = encoding.ReadObject(conn, &id, crypto.HashSize); err != nil { | ||
err = errors.New("unable to read 'ids': " + err.Error()) | ||
return | ||
} | ||
} | ||
return | ||
} |