-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
156 additions
and
38 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
Binary file not shown.
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
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,56 @@ | ||
package object | ||
|
||
import ( | ||
"fmt" | ||
|
||
enc "github.com/named-data/ndnd/std/encoding" | ||
"github.com/named-data/ndnd/std/ndn" | ||
sec "github.com/named-data/ndnd/std/security" | ||
) | ||
|
||
// Validate a data packet using the client configuration | ||
func (c *Client) Validate(data ndn.Data, callback func(bool, error)) { | ||
if c.trust == nil { | ||
callback(true, nil) | ||
return | ||
} | ||
|
||
// Pop off the version and segment components | ||
name := data.Name() | ||
if len(name) > 2 { | ||
if name[len(name)-1].Typ == enc.TypeSegmentNameComponent { | ||
name = name[:len(name)-1] | ||
} | ||
if name[len(name)-1].Typ == enc.TypeVersionNameComponent { | ||
name = name[:len(name)-1] | ||
} | ||
} | ||
|
||
// Add to queue of validation | ||
select { | ||
case c.validatepipe <- sec.ValidateArgs{ | ||
Data: data, | ||
Callback: callback, | ||
DataName: name, | ||
Fetch: func(name enc.Name, config *ndn.InterestConfig, found func(ndn.Data, []byte, error)) { | ||
c.ExpressR(ndn.ExpressRArgs{ | ||
Name: name, | ||
Config: config, | ||
Retries: 3, | ||
Callback: func(res ndn.ExpressCallbackArgs) { | ||
if res.Result == ndn.InterestResultData { | ||
found(res.Data, res.RawData.Join(), nil) | ||
} else if res.Error != nil { | ||
found(nil, nil, res.Error) | ||
} else { | ||
found(nil, nil, fmt.Errorf("failed to fetch certificate (%s) with result: %v", name, res.Result)) | ||
} | ||
}, | ||
}) | ||
}, | ||
}: | ||
// Queued successfully | ||
default: | ||
callback(false, fmt.Errorf("validation queue full")) | ||
} | ||
} |
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.