diff --git a/cmd/node-canary/main.go b/cmd/node-canary/main.go index 70e3f98a7..e7c0403c4 100644 --- a/cmd/node-canary/main.go +++ b/cmd/node-canary/main.go @@ -12,7 +12,6 @@ import ( "path/filepath" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" @@ -22,9 +21,12 @@ import ( "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/services/shhext" "github.com/status-im/status-go/t/helpers" - whisper "github.com/status-im/whisper/whisperv6" + "github.com/status-im/status-protocol-go/transport/whisper/gethbridge" + statusproto "github.com/status-im/status-protocol-go/types" "golang.org/x/crypto/sha3" "golang.org/x/crypto/ssh/terminal" + + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" ) const ( @@ -105,11 +107,12 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) { defer func() { _ = clientBackend.StopNode() }() clientNode := clientBackend.StatusNode() - clientWhisperService, err := clientNode.WhisperService() + clientGethWhisperService, err := clientNode.WhisperService() if err != nil { logger.Error("Could not retrieve Whisper service", "error", err) os.Exit(1) } + clientWhisperService := gethbridge.NewGethWhisperWrapper(clientGethWhisperService) clientShhExtService, err := clientNode.ShhExtService() if err != nil { logger.Error("Could not retrieve shhext service", "error", err) @@ -139,7 +142,7 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) { } mailboxPeer := mailserverNode.ID().Bytes() - err = clientWhisperService.AllowP2PMessagesFromPeer(mailboxPeer) + err = clientGethWhisperService.AllowP2PMessagesFromPeer(mailboxPeer) if err != nil { logger.Error("Failed to allow P2P messages from mailserver peer", "error", err, mailserverNode.String()) os.Exit(1) @@ -155,12 +158,12 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) { } // watch for envelopes to be available in filters in the client - envelopeAvailableWatcher := make(chan whisper.EnvelopeEvent, 1024) + envelopeAvailableWatcher := make(chan whispertypes.EnvelopeEvent, 1024) sub := clientWhisperService.SubscribeEnvelopeEvents(envelopeAvailableWatcher) defer sub.Unsubscribe() // watch for mailserver responses in the client - mailServerResponseWatcher := make(chan whisper.EnvelopeEvent, 1024) + mailServerResponseWatcher := make(chan whispertypes.EnvelopeEvent, 1024) sub = clientWhisperService.SubscribeEnvelopeEvents(mailServerResponseWatcher) defer sub.Unsubscribe() @@ -179,7 +182,7 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) { logger.Error("Error requesting historic messages from mailserver", "error", err) os.Exit(2) } - requestID := common.BytesToHash(requestIDBytes) + requestID := statusproto.BytesToHash(requestIDBytes) // wait for mailserver request sent event err = waitForMailServerRequestSent(mailServerResponseWatcher, requestID, time.Duration(*timeout)*time.Second) @@ -196,7 +199,7 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) { } // wait for last envelope sent by the mailserver to be available for filters - err = waitForEnvelopeEvents(envelopeAvailableWatcher, []string{resp.LastEnvelopeHash.String()}, whisper.EventEnvelopeAvailable) + err = waitForEnvelopeEvents(envelopeAvailableWatcher, []string{resp.LastEnvelopeHash.String()}, whispertypes.EventEnvelopeAvailable) if err != nil { logger.Error("Error waiting for envelopes to be available to client filter", "error", err) os.Exit(4) @@ -300,32 +303,32 @@ func startClientNode() (*api.StatusBackend, error) { return clientBackend, err } -func joinPublicChat(w *whisper.Whisper, rpcClient *rpc.Client, name string) (string, whisper.TopicType, string, error) { +func joinPublicChat(w whispertypes.Whisper, rpcClient *rpc.Client, name string) (string, whispertypes.TopicType, string, error) { keyID, err := w.AddSymKeyFromPassword(name) if err != nil { - return "", whisper.TopicType{}, "", err + return "", whispertypes.TopicType{}, "", err } h := sha3.NewLegacyKeccak256() _, err = h.Write([]byte(name)) if err != nil { - return "", whisper.TopicType{}, "", err + return "", whispertypes.TopicType{}, "", err } fullTopic := h.Sum(nil) - topic := whisper.BytesToTopic(fullTopic) + topic := whispertypes.BytesToTopic(fullTopic) - whisperAPI := whisper.NewPublicWhisperAPI(w) - filterID, err := whisperAPI.NewMessageFilter(whisper.Criteria{SymKeyID: keyID, Topics: []whisper.TopicType{topic}}) + whisperAPI := w.PublicWhisperAPI() + filterID, err := whisperAPI.NewMessageFilter(whispertypes.Criteria{SymKeyID: keyID, Topics: []whispertypes.TopicType{topic}}) return keyID, topic, filterID, err } -func waitForMailServerRequestSent(events chan whisper.EnvelopeEvent, requestID common.Hash, timeout time.Duration) error { +func waitForMailServerRequestSent(events chan whispertypes.EnvelopeEvent, requestID statusproto.Hash, timeout time.Duration) error { timeoutTimer := time.NewTimer(timeout) for { select { case event := <-events: - if event.Hash == requestID && event.Event == whisper.EventMailServerRequestSent { + if event.Hash == requestID && event.Event == whispertypes.EventMailServerRequestSent { timeoutTimer.Stop() return nil } @@ -335,7 +338,7 @@ func waitForMailServerRequestSent(events chan whisper.EnvelopeEvent, requestID c } } -func waitForMailServerResponse(events chan whisper.EnvelopeEvent, requestID common.Hash, timeout time.Duration) (*whisper.MailServerResponse, error) { +func waitForMailServerResponse(events chan whispertypes.EnvelopeEvent, requestID statusproto.Hash, timeout time.Duration) (*whispertypes.MailServerResponse, error) { timeoutTimer := time.NewTimer(timeout) for { select { @@ -353,25 +356,25 @@ func waitForMailServerResponse(events chan whisper.EnvelopeEvent, requestID comm } } -func decodeMailServerResponse(event whisper.EnvelopeEvent) (*whisper.MailServerResponse, error) { +func decodeMailServerResponse(event whispertypes.EnvelopeEvent) (*whispertypes.MailServerResponse, error) { switch event.Event { - case whisper.EventMailServerRequestSent: + case whispertypes.EventMailServerRequestSent: return nil, nil - case whisper.EventMailServerRequestCompleted: - resp, ok := event.Data.(*whisper.MailServerResponse) + case whispertypes.EventMailServerRequestCompleted: + resp, ok := event.Data.(*whispertypes.MailServerResponse) if !ok { return nil, errors.New("failed to convert event to a *MailServerResponse") } return resp, nil - case whisper.EventMailServerRequestExpired: + case whispertypes.EventMailServerRequestExpired: return nil, errors.New("no messages available from mailserver") default: return nil, fmt.Errorf("unexpected event type: %v", event.Event) } } -func waitForEnvelopeEvents(events chan whisper.EnvelopeEvent, hashes []string, event whisper.EventType) error { +func waitForEnvelopeEvents(events chan whispertypes.EnvelopeEvent, hashes []string, event whispertypes.EventType) error { check := make(map[string]struct{}) for _, hash := range hashes { check[hash] = struct{}{} diff --git a/db/history.go b/db/history.go index 5e5f5b048..288e09756 100644 --- a/db/history.go +++ b/db/history.go @@ -6,8 +6,8 @@ import ( "errors" "time" - "github.com/ethereum/go-ethereum/common" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/syndtr/goleveldb/leveldb/util" ) @@ -26,7 +26,7 @@ type DB interface { } // TopicHistoryKey defines bytes that are used as unique key for TopicHistory. -// first 4 bytes are whisper.TopicType bytes +// first 4 bytes are whispertypes.TopicType bytes // next 8 bytes are time.Duration encoded in big endian notation. type TopicHistoryKey [12]byte @@ -36,7 +36,7 @@ func LoadTopicHistoryFromKey(db DB, key TopicHistoryKey) (th TopicHistory, err e if (key == TopicHistoryKey{}) { return th, ErrEmptyKey } - topic := whisper.TopicType{} + topic := whispertypes.TopicType{} copy(topic[:], key[:4]) duration := binary.BigEndian.Uint64(key[4:]) th = TopicHistory{db: db, Topic: topic, Duration: time.Duration(duration)} @@ -47,7 +47,7 @@ func LoadTopicHistoryFromKey(db DB, key TopicHistoryKey) (th TopicHistory, err e type TopicHistory struct { db DB // whisper topic - Topic whisper.TopicType + Topic whispertypes.TopicType Duration time.Duration // Timestamp that was used for the first request with this topic. @@ -57,7 +57,7 @@ type TopicHistory struct { Current time.Time End time.Time - RequestID common.Hash + RequestID statusproto.Hash } // Key returns unique identifier for this TopicHistory. @@ -115,7 +115,7 @@ func (t TopicHistory) SameRange(other TopicHistory) bool { // Pending returns true if this topic was requested from a mail server. func (t TopicHistory) Pending() bool { - return t.RequestID != common.Hash{} + return t.RequestID != statusproto.Hash{} } // HistoryRequest is kept in the database while request is in the progress. @@ -127,7 +127,7 @@ type HistoryRequest struct { histories []TopicHistory // Generated ID - ID common.Hash + ID statusproto.Hash // List of the topics TopicHistoryKeys []TopicHistoryKey } @@ -167,8 +167,8 @@ func (req HistoryRequest) Save() error { } // Replace saves request with new ID and all data attached to the old one. -func (req HistoryRequest) Replace(id common.Hash) error { - if (req.ID != common.Hash{}) { +func (req HistoryRequest) Replace(id statusproto.Hash) error { + if (req.ID != statusproto.Hash{}) { if err := req.Delete(); err != nil { return err } diff --git a/db/history_store.go b/db/history_store.go index 2597feb0c..b2f31bc94 100644 --- a/db/history_store.go +++ b/db/history_store.go @@ -3,8 +3,8 @@ package db import ( "time" - "github.com/ethereum/go-ethereum/common" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/syndtr/goleveldb/leveldb/errors" ) @@ -24,7 +24,7 @@ type HistoryStore struct { // GetHistory creates history instance and loads history from database. // Returns instance populated with topic and duration if history is not found in database. -func (h HistoryStore) GetHistory(topic whisper.TopicType, duration time.Duration) (TopicHistory, error) { +func (h HistoryStore) GetHistory(topic whispertypes.TopicType, duration time.Duration) (TopicHistory, error) { thist := h.NewHistory(topic, duration) err := thist.Load() if err != nil && err != errors.ErrNotFound { @@ -39,12 +39,12 @@ func (h HistoryStore) NewRequest() HistoryRequest { } // NewHistory creates TopicHistory object with required values. -func (h HistoryStore) NewHistory(topic whisper.TopicType, duration time.Duration) TopicHistory { +func (h HistoryStore) NewHistory(topic whispertypes.TopicType, duration time.Duration) TopicHistory { return TopicHistory{db: h.topicDB, Duration: duration, Topic: topic} } // GetRequest loads HistoryRequest from database. -func (h HistoryStore) GetRequest(id common.Hash) (HistoryRequest, error) { +func (h HistoryStore) GetRequest(id statusproto.Hash) (HistoryRequest, error) { req := HistoryRequest{requestDB: h.requestDB, topicDB: h.topicDB, ID: id} err := req.Load() if err != nil { @@ -74,7 +74,7 @@ func (h HistoryStore) GetAllRequests() ([]HistoryRequest, error) { // GetHistoriesByTopic returns all histories with a given topic. // This is needed when we will have multiple range per single topic. // TODO explain -func (h HistoryStore) GetHistoriesByTopic(topic whisper.TopicType) ([]TopicHistory, error) { +func (h HistoryStore) GetHistoriesByTopic(topic whispertypes.TopicType) ([]TopicHistory, error) { rst := []TopicHistory{} iter := h.topicDB.NewIterator(h.topicDB.Range(topic[:], nil)) for iter.Next() { diff --git a/db/history_store_test.go b/db/history_store_test.go index 48228b3c2..337c2dd44 100644 --- a/db/history_store_test.go +++ b/db/history_store_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/stretchr/testify/require" ) @@ -16,7 +16,7 @@ func createInMemStore(t *testing.T) HistoryStore { } func TestGetNewHistory(t *testing.T) { - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} duration := time.Hour store := createInMemStore(t) th, err := store.GetHistory(topic, duration) @@ -26,7 +26,7 @@ func TestGetNewHistory(t *testing.T) { } func TestGetExistingHistory(t *testing.T) { - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} duration := time.Hour store := createInMemStore(t) th, err := store.GetHistory(topic, duration) @@ -43,13 +43,13 @@ func TestGetExistingHistory(t *testing.T) { func TestNewHistoryRequest(t *testing.T) { store := createInMemStore(t) - id := common.Hash{1} + id := statusproto.Hash{1} req, err := store.GetRequest(id) require.Error(t, err) req = store.NewRequest() req.ID = id - th, err := store.GetHistory(whisper.TopicType{1}, time.Hour) + th, err := store.GetHistory(whispertypes.TopicType{1}, time.Hour) require.NoError(t, err) req.AddHistory(th) require.NoError(t, req.Save()) @@ -61,8 +61,8 @@ func TestNewHistoryRequest(t *testing.T) { func TestGetAllRequests(t *testing.T) { store := createInMemStore(t) - idOne := common.Hash{1} - idTwo := common.Hash{2} + idOne := statusproto.Hash{1} + idTwo := statusproto.Hash{2} req := store.NewRequest() req.ID = idOne diff --git a/db/history_test.go b/db/history_test.go index f746ca12a..d3b6f296f 100644 --- a/db/history_test.go +++ b/db/history_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/stretchr/testify/require" ) @@ -14,7 +14,7 @@ func TestTopicHistoryStoreLoadFromKey(t *testing.T) { require.NoError(t, err) th := TopicHistory{ db: db, - Topic: whisper.TopicType{1, 1, 1}, + Topic: whispertypes.TopicType{1, 1, 1}, Duration: 10 * time.Hour, } require.NoError(t, th.Save()) @@ -71,7 +71,7 @@ func TestTopicHistorySameRange(t *testing.T) { } func TestAddHistory(t *testing.T) { - topic := whisper.TopicType{1, 1, 1} + topic := whispertypes.TopicType{1, 1, 1} now := time.Now() topicdb, err := NewMemoryDBNamespace(TopicHistoryBucket) @@ -80,7 +80,7 @@ func TestAddHistory(t *testing.T) { require.NoError(t, err) th := TopicHistory{db: topicdb, Topic: topic, Current: now} - id := common.Hash{1} + id := statusproto.Hash{1} req := HistoryRequest{requestDB: requestdb, topicDB: topicdb, ID: id} req.AddHistory(th) @@ -94,8 +94,8 @@ func TestAddHistory(t *testing.T) { } func TestRequestIncludesMethod(t *testing.T) { - topicOne := whisper.TopicType{1} - topicTwo := whisper.TopicType{2} + topicOne := whispertypes.TopicType{1} + topicTwo := whispertypes.TopicType{2} testCases := []struct { description string result bool diff --git a/go.mod b/go.mod index e72fe8611..83f094cf8 100644 --- a/go.mod +++ b/go.mod @@ -30,10 +30,8 @@ require ( github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 // indirect github.com/status-im/migrate/v4 v4.3.1-status.0.20190822050738-a9d340ec8fb7 github.com/status-im/rendezvous v1.3.0 - github.com/status-im/status-protocol-go v0.2.3-0.20190926081215-cc44ddb7ce44 - github.com/status-im/whisper v1.4.14 - github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 // indirect - github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect + github.com/status-im/status-protocol-go v0.2.3-0.20191009073015-e7ecec99a52b + github.com/status-im/whisper v1.5.1 github.com/stretchr/testify v1.4.0 github.com/syndtr/goleveldb v1.0.0 github.com/tyler-smith/go-bip39 v1.0.2 // indirect diff --git a/go.sum b/go.sum index 5c2dde804..dbf3e1d86 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,11 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/allegro/bigcache v0.0.0-20190218064605-e24eb225f156 h1:hh7BAWFHv41r0gce0KRYtDJpL4erKfmB1/mpgoSADeI= github.com/allegro/bigcache v0.0.0-20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/allegro/bigcache v1.1.0 h1:MLuIKTjdxDc+qsG2rhjsYjsHQC5LUGjIWzutg7M+W68= +github.com/allegro/bigcache v1.1.0/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= +github.com/aristanetworks/goarista v0.0.0-20181002214814-33151c4543a7/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/aristanetworks/goarista v0.0.0-20190502180301-283422fc1708/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/aristanetworks/goarista v0.0.0-20190704150520-f44d68189fd7 h1:fKnuvQ/O22ZpD7HaJjGQXn/GxOdDJOQFL8bpM8Xe3X8= github.com/aristanetworks/goarista v0.0.0-20190704150520-f44d68189fd7/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= @@ -41,6 +44,7 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= +github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= @@ -115,7 +119,6 @@ github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt github.com/elastic/gosigar v0.0.0-20180330100440-37f05ff46ffa h1:o8OuEkracbk3qH6GvlI6XpEN1HTSxkzOG42xZpfDv/s= github.com/elastic/gosigar v0.0.0-20180330100440-37f05ff46ffa/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs= github.com/ethereum/go-ethereum v1.8.20/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= -github.com/ethereum/go-ethereum v1.8.27/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc h1:jtW8jbpkO4YirRSyepBOH8E+2HEw6/hKkBvFPwhUN8c= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= @@ -459,9 +462,13 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= +github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= @@ -549,10 +556,10 @@ github.com/status-im/migrate/v4 v4.3.1-status.0.20190822050738-a9d340ec8fb7 h1:g github.com/status-im/migrate/v4 v4.3.1-status.0.20190822050738-a9d340ec8fb7/go.mod h1:r8HggRBZ/k7TRwByq/Hp3P/ubFppIna0nvyavVK0pjA= github.com/status-im/rendezvous v1.3.0 h1:7RK/MXXW+tlm0asKm1u7Qp7Yni6AO29a7j8+E4Lbjg4= github.com/status-im/rendezvous v1.3.0/go.mod h1:+hzjuP+j/XzLPeF6E50b88pWOTLdTcwjvNYt+Gh1W1s= -github.com/status-im/status-protocol-go v0.2.3-0.20190926081215-cc44ddb7ce44 h1:/dyB9wnkkNURvznzewDov3ulnLbjl8h1OeEEr5NQmQM= -github.com/status-im/status-protocol-go v0.2.3-0.20190926081215-cc44ddb7ce44/go.mod h1:g059a1CeUmHKzsokiKwdk5pCuhCPE1GeOh8vULbfn5w= -github.com/status-im/whisper v1.4.14 h1:9VHqx4+PUYfhDnYYtDxHkg/3cfVvkHjPNciY4LO83yc= -github.com/status-im/whisper v1.4.14/go.mod h1:WS6z39YJQ8WJa9s+DmTuEM/s2nVF6Iz3B1SZYw5cYf0= +github.com/status-im/status-protocol-go v0.2.3-0.20191009073015-e7ecec99a52b h1:hCB3tnF1yJ/IN0v+zR+Omc5DKUyUPyrrhyYkJUupnSw= +github.com/status-im/status-protocol-go v0.2.3-0.20191009073015-e7ecec99a52b/go.mod h1:z4P5yngpR7aB6N6uYtJnhOkHzDHAHlqxTbIbaSX72Jg= +github.com/status-im/whisper v1.5.1 h1:87/XIg0Wjua7lXBGiEXgAfTOqlt2Q1dMDuxugTyZbbA= +github.com/status-im/whisper v1.5.1/go.mod h1:emrOxzJme0k66QtbbQ2bdd3P8RCdLZ8sTD7SkwH1s2s= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM= diff --git a/node/node.go b/node/node.go index 642446d2e..4478cf3c0 100644 --- a/node/node.go +++ b/node/node.go @@ -32,6 +32,8 @@ import ( "github.com/status-im/status-go/services/status" "github.com/status-im/status-go/static" "github.com/status-im/status-go/timesource" + "github.com/status-im/status-protocol-go/transport/whisper/gethbridge" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" whisper "github.com/status-im/whisper/whisperv6" "github.com/syndtr/goleveldb/leveldb" ) @@ -356,7 +358,7 @@ func activateShhService(stack *node.Node, config *params.NodeConfig, db *leveldb if err := ctx.Service(&whisper); err != nil { return nil, err } - return shhext.New(whisper, shhext.EnvelopeSignalHandler{}, db, config.ShhextConfig), nil + return shhext.New(gethbridge.NewGethWhisperWrapper(whisper), shhext.EnvelopeSignalHandler{}, db, config.ShhextConfig), nil }) } @@ -375,7 +377,7 @@ func activateIncentivisationService(stack *node.Node, config *params.NodeConfig) logger.Info("activating incentivisation") // TODO(dshulyak) add a config option to enable it by default, but disable if app is started from statusd return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { - var w *whisper.Whisper + var w whispertypes.Whisper if err := ctx.Service(&w); err != nil { return nil, err } @@ -399,7 +401,7 @@ func activateIncentivisationService(stack *node.Node, config *params.NodeConfig) return nil, err } - return incentivisation.New(privateKey, whisper.NewPublicWhisperAPI(w), incentivisationConfig, contract), nil + return incentivisation.New(privateKey, w.PublicWhisperAPI(), incentivisationConfig, contract), nil }) } diff --git a/node/node_api_test.go b/node/node_api_test.go index 7ab62ebbc..5a762ec79 100644 --- a/node/node_api_test.go +++ b/node/node_api_test.go @@ -4,9 +4,9 @@ import ( "testing" "github.com/ethereum/go-ethereum/accounts" - whisper "github.com/status-im/whisper/whisperv6" "github.com/status-im/status-go/params" + whisper "github.com/status-im/whisper/whisperv6" "github.com/stretchr/testify/require" ) diff --git a/services/incentivisation/service.go b/services/incentivisation/service.go index 394970b49..bae127c9c 100644 --- a/services/incentivisation/service.go +++ b/services/incentivisation/service.go @@ -8,6 +8,10 @@ import ( "encoding/binary" "encoding/hex" "fmt" + "math/big" + "net" + "sort" + "github.com/ethereum/go-ethereum/accounts/abi/bind" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -15,12 +19,11 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rpc" - "math/big" - "net" - "sort" - whisper "github.com/status-im/whisper/whisperv6" "time" + + statustransp "github.com/status-im/status-protocol-go/transport/whisper" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" ) const ( @@ -51,15 +54,6 @@ func (n *Enode) PublicKeyString() string { return hex.EncodeToString(n.PublicKey) } -type Whisper interface { - Post(ctx context.Context, req whisper.NewMessage) (hexutil.Bytes, error) - NewMessageFilter(req whisper.Criteria) (string, error) - AddPrivateKey(ctx context.Context, privateKey hexutil.Bytes) (string, error) - DeleteKeyPair(ctx context.Context, key string) (bool, error) - GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) - GetFilterMessages(id string) ([]*whisper.Message, error) -} - type ServiceConfig struct { RPCEndpoint string ContractAddress string @@ -68,7 +62,7 @@ type ServiceConfig struct { } type Service struct { - w Whisper + w whispertypes.PublicWhisperAPI whisperKeyID string whisperSymKeyID string whisperFilterID string @@ -87,7 +81,7 @@ type Service struct { } // New returns a new incentivization Service -func New(prv *ecdsa.PrivateKey, w Whisper, config *ServiceConfig, contract Contract) *Service { +func New(prv *ecdsa.PrivateKey, w whispertypes.PublicWhisperAPI, config *ServiceConfig, contract Contract) *Service { logger := log.New("package", "status-go/incentivisation/service") return &Service{ w: w, @@ -307,9 +301,9 @@ func (s *Service) Start(server *p2p.Server) error { } s.whisperSymKeyID = whisperSymKeyID - criteria := whisper.Criteria{ + criteria := whispertypes.Criteria{ SymKeyID: whisperSymKeyID, - Topics: []whisper.TopicType{toWhisperTopic(defaultTopic)}, + Topics: []whispertypes.TopicType{toWhisperTopic(defaultTopic)}, } filterID, err := s.w.NewMessageFilter(criteria) if err != nil { @@ -437,7 +431,7 @@ func (s *Service) addressString() string { // postPing publishes a whisper message func (s *Service) postPing() (hexutil.Bytes, error) { - msg := defaultWhisperMessage() + msg := statustransp.DefaultWhisperMessage() msg.Topic = toWhisperTopic(defaultTopic) @@ -484,18 +478,8 @@ func ip2Long(ip string) (uint32, error) { return long, nil } -func toWhisperTopic(s string) whisper.TopicType { - return whisper.BytesToTopic(crypto.Keccak256([]byte(s))) -} - -func defaultWhisperMessage() whisper.NewMessage { - msg := whisper.NewMessage{} - - msg.TTL = 10 - msg.PowTarget = 0.002 - msg.PowTime = 1 - - return msg +func toWhisperTopic(s string) whispertypes.TopicType { + return whispertypes.BytesToTopic(crypto.Keccak256([]byte(s))) } func int2ip(nn uint32) net.IP { diff --git a/services/incentivisation/service_test.go b/services/incentivisation/service_test.go index 94777054f..55649c0b9 100644 --- a/services/incentivisation/service_test.go +++ b/services/incentivisation/service_test.go @@ -9,10 +9,10 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" gethcommon "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/stretchr/testify/suite" ) @@ -34,8 +34,8 @@ type Vote struct { } type MockWhisper struct { - sentMessages []whisper.NewMessage - filterMessages []*whisper.Message + sentMessages []whispertypes.NewMessage + filterMessages []*whispertypes.Message } func BuildMockContract() *MockContract { @@ -99,14 +99,14 @@ func (c *MockContract) GetInactiveNode(opts *bind.CallOpts, index *big.Int) ([]b return c.inactiveNodes[index.Int64()], 0, 0, 0, 0, nil } -func (w *MockWhisper) Post(ctx context.Context, req whisper.NewMessage) (hexutil.Bytes, error) { +func (w *MockWhisper) Post(ctx context.Context, req whispertypes.NewMessage) ([]byte, error) { w.sentMessages = append(w.sentMessages, req) return nil, nil } -func (w *MockWhisper) NewMessageFilter(req whisper.Criteria) (string, error) { +func (w *MockWhisper) NewMessageFilter(req whispertypes.Criteria) (string, error) { return "", nil } -func (w *MockWhisper) AddPrivateKey(ctx context.Context, privateKey hexutil.Bytes) (string, error) { +func (w *MockWhisper) AddPrivateKey(ctx context.Context, privateKey statusproto.HexBytes) (string, error) { return "", nil } func (w *MockWhisper) DeleteKeyPair(ctx context.Context, key string) (bool, error) { @@ -115,7 +115,7 @@ func (w *MockWhisper) DeleteKeyPair(ctx context.Context, key string) (bool, erro func (w *MockWhisper) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) { return "", nil } -func (w *MockWhisper) GetFilterMessages(id string) ([]*whisper.Message, error) { +func (w *MockWhisper) GetFilterMessages(id string) ([]*whispertypes.Message, error) { return w.filterMessages, nil } @@ -164,7 +164,7 @@ func (s *IncentivisationSuite) TestPerform() { now := time.Now().Unix() // Add some envelopes - s.mockWhisper.filterMessages = []*whisper.Message{ + s.mockWhisper.filterMessages = []*whispertypes.Message{ { // We strip the first byte when processing Sig: append(nodeOne, nodeOne[0]), diff --git a/services/shhext/api.go b/services/shhext/api.go index a4ee55a3f..0195a2a92 100644 --- a/services/shhext/api.go +++ b/services/shhext/api.go @@ -9,8 +9,6 @@ import ( "math/big" "time" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p/enode" @@ -25,6 +23,9 @@ import ( statusproto "github.com/status-im/status-protocol-go" "github.com/status-im/status-protocol-go/encryption/multidevice" statustransp "github.com/status-im/status-protocol-go/transport/whisper" + "github.com/status-im/status-protocol-go/transport/whisper/gethbridge" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto_types "github.com/status-im/status-protocol-go/types" ) const ( @@ -73,10 +74,10 @@ type MessagesRequest struct { // Topic is a regular Whisper topic. // DEPRECATED - Topic whisper.TopicType `json:"topic"` + Topic whispertypes.TopicType `json:"topic"` // Topics is a list of Whisper topics. - Topics []whisper.TopicType `json:"topics"` + Topics []whispertypes.TopicType `json:"topics"` // SymKeyID is an ID of a symmetric key to authenticate to MailServer. // It's derived from MailServer password. @@ -146,7 +147,7 @@ type SyncMessagesRequest struct { // Topics is a list of Whisper topics. // If empty, a full bloom filter will be used. - Topics []whisper.TopicType `json:"topics"` + Topics []whispertypes.TopicType `json:"topics"` } // SyncMessagesResponse is a response from the mail server @@ -177,7 +178,7 @@ type InitiateHistoryRequestParams struct { // PublicAPI extends whisper public API. type PublicAPI struct { service *Service - publicAPI *whisper.PublicWhisperAPI + publicAPI whispertypes.PublicWhisperAPI log log.Logger } @@ -185,7 +186,7 @@ type PublicAPI struct { func NewPublicAPI(s *Service) *PublicAPI { return &PublicAPI{ service: s, - publicAPI: whisper.NewPublicWhisperAPI(s.w), + publicAPI: s.w.PublicWhisperAPI(), log: log.New("package", "status-go/services/sshext.PublicAPI"), } } @@ -210,9 +211,9 @@ func (api *PublicAPI) RequestMessagesSync(conf RetryConfig, r MessagesRequest) ( var resp MessagesResponse shh := api.service.w - events := make(chan whisper.EnvelopeEvent, 10) + events := make(chan whispertypes.EnvelopeEvent, 10) var ( - requestID hexutil.Bytes + requestID statusproto_types.HexBytes err error retries int ) @@ -227,7 +228,7 @@ func (api *PublicAPI) RequestMessagesSync(conf RetryConfig, r MessagesRequest) ( sub.Unsubscribe() return resp, err } - mailServerResp, err := waitForExpiredOrCompleted(common.BytesToHash(requestID), events, timeout) + mailServerResp, err := waitForExpiredOrCompleted(statusproto_types.BytesToHash(requestID), events, timeout) sub.Unsubscribe() if err == nil { resp.Cursor = hex.EncodeToString(mailServerResp.Cursor) @@ -240,12 +241,12 @@ func (api *PublicAPI) RequestMessagesSync(conf RetryConfig, r MessagesRequest) ( return resp, fmt.Errorf("failed to request messages after %d retries", retries) } -func waitForExpiredOrCompleted(requestID common.Hash, events chan whisper.EnvelopeEvent, timeout time.Duration) (*whisper.MailServerResponse, error) { +func waitForExpiredOrCompleted(requestID statusproto_types.Hash, events chan whispertypes.EnvelopeEvent, timeout time.Duration) (*whispertypes.MailServerResponse, error) { expired := fmt.Errorf("request %x expired", requestID) after := time.NewTimer(timeout) defer after.Stop() for { - var ev whisper.EnvelopeEvent + var ev whispertypes.EnvelopeEvent select { case ev = <-events: case <-after.C: @@ -255,20 +256,20 @@ func waitForExpiredOrCompleted(requestID common.Hash, events chan whisper.Envelo continue } switch ev.Event { - case whisper.EventMailServerRequestCompleted: - data, ok := ev.Data.(*whisper.MailServerResponse) + case whispertypes.EventMailServerRequestCompleted: + data, ok := ev.Data.(*whispertypes.MailServerResponse) if ok { return data, nil } return nil, errors.New("invalid event data type") - case whisper.EventMailServerRequestExpired: + case whispertypes.EventMailServerRequestExpired: return nil, expired } } } // RequestMessages sends a request for historic messages to a MailServer. -func (api *PublicAPI) RequestMessages(_ context.Context, r MessagesRequest) (hexutil.Bytes, error) { +func (api *PublicAPI) RequestMessages(_ context.Context, r MessagesRequest) (statusproto_types.HexBytes, error) { api.log.Info("RequestMessages", "request", r) shh := api.service.w now := api.service.w.GetCurrentTime() @@ -334,20 +335,20 @@ func (api *PublicAPI) RequestMessages(_ context.Context, r MessagesRequest) (hex // createSyncMailRequest creates SyncMailRequest. It uses a full bloom filter // if no topics are given. -func createSyncMailRequest(r SyncMessagesRequest) (whisper.SyncMailRequest, error) { +func createSyncMailRequest(r SyncMessagesRequest) (whispertypes.SyncMailRequest, error) { var bloom []byte if len(r.Topics) > 0 { bloom = topicsToBloom(r.Topics...) } else { - bloom = whisper.MakeFullNodeBloom() + bloom = whispertypes.MakeFullNodeBloom() } cursor, err := hex.DecodeString(r.Cursor) if err != nil { - return whisper.SyncMailRequest{}, err + return whispertypes.SyncMailRequest{}, err } - return whisper.SyncMailRequest{ + return whispertypes.SyncMailRequest{ Lower: r.From, Upper: r.To, Bloom: bloom, @@ -356,7 +357,7 @@ func createSyncMailRequest(r SyncMessagesRequest) (whisper.SyncMailRequest, erro }, nil } -func createSyncMessagesResponse(r whisper.SyncEventResponse) SyncMessagesResponse { +func createSyncMessagesResponse(r whispertypes.SyncEventResponse) SyncMessagesResponse { return SyncMessagesResponse{ Cursor: hex.EncodeToString(r.Cursor), Error: r.Error, @@ -423,7 +424,7 @@ func (api *PublicAPI) ConfirmMessagesProcessedByID(messageConfirmations []*dedup // in other words don't use PFS-enabled messages. Otherwise, SendDirectMessage is used. // It's important to call PublicAPI.afterSend() so that the client receives a signal // with confirmation that the message left the device. -func (api *PublicAPI) Post(ctx context.Context, newMessage whisper.NewMessage) (hexutil.Bytes, error) { +func (api *PublicAPI) Post(ctx context.Context, newMessage whispertypes.NewMessage) (statusproto_types.HexBytes, error) { return api.publicAPI.Post(ctx, newMessage) } @@ -431,7 +432,7 @@ func (api *PublicAPI) Post(ctx context.Context, newMessage whisper.NewMessage) ( // Message's payload is a transit encoded message. // It's important to call PublicAPI.afterSend() so that the client receives a signal // with confirmation that the message left the device. -func (api *PublicAPI) SendPublicMessage(ctx context.Context, msg SendPublicMessageRPC) (hexutil.Bytes, error) { +func (api *PublicAPI) SendPublicMessage(ctx context.Context, msg SendPublicMessageRPC) (statusproto_types.HexBytes, error) { chat := statusproto.Chat{ Name: msg.Chat, } @@ -442,7 +443,7 @@ func (api *PublicAPI) SendPublicMessage(ctx context.Context, msg SendPublicMessa // Message's payload is a transit encoded message. // It's important to call PublicAPI.afterSend() so that the client receives a signal // with confirmation that the message left the device. -func (api *PublicAPI) SendDirectMessage(ctx context.Context, msg SendDirectMessageRPC) (hexutil.Bytes, error) { +func (api *PublicAPI) SendDirectMessage(ctx context.Context, msg SendDirectMessageRPC) (statusproto_types.HexBytes, error) { publicKey, err := crypto.UnmarshalPubkey(msg.PubKey) if err != nil { return nil, err @@ -454,7 +455,7 @@ func (api *PublicAPI) SendDirectMessage(ctx context.Context, msg SendDirectMessa return api.service.messenger.SendRaw(ctx, chat, msg.Payload) } -func (api *PublicAPI) requestMessagesUsingPayload(request db.HistoryRequest, peer, symkeyID string, payload []byte, force bool, timeout time.Duration, topics []whisper.TopicType) (hash common.Hash, err error) { +func (api *PublicAPI) requestMessagesUsingPayload(request db.HistoryRequest, peer, symkeyID string, payload []byte, force bool, timeout time.Duration, topics []whispertypes.TopicType) (hash statusproto_types.Hash, err error) { shh := api.service.w now := api.service.w.GetCurrentTime() @@ -518,7 +519,7 @@ func (api *PublicAPI) requestMessagesUsingPayload(request db.HistoryRequest, pee // - Topic // - Duration in nanoseconds. Will be used to determine starting time for history request. // After that status-go will guarantee that request for this topic and date will be performed. -func (api *PublicAPI) InitiateHistoryRequests(parent context.Context, request InitiateHistoryRequestParams) (rst []hexutil.Bytes, err error) { +func (api *PublicAPI) InitiateHistoryRequests(parent context.Context, request InitiateHistoryRequestParams) (rst []statusproto_types.HexBytes, err error) { tx := api.service.storage.NewTx() defer func() { if err == nil { @@ -532,7 +533,7 @@ func (api *PublicAPI) InitiateHistoryRequests(parent context.Context, request In } var ( payload []byte - hash common.Hash + hash statusproto_types.Hash ) for i := range requests { req := requests[i] @@ -555,7 +556,7 @@ func (api *PublicAPI) InitiateHistoryRequests(parent context.Context, request In func (api *PublicAPI) CompleteRequest(parent context.Context, hex string) (err error) { tx := api.service.storage.NewTx() ctx := NewContextFromService(parent, api.service, tx) - err = api.service.historyUpdates.UpdateFinishedRequest(ctx, common.HexToHash(hex)) + err = api.service.historyUpdates.UpdateFinishedRequest(ctx, statusproto_types.HexToHash(hex)) if err == nil { return tx.Commit() } @@ -667,7 +668,7 @@ func makeEnvelop( nodeID *ecdsa.PrivateKey, pow float64, now time.Time, -) (*whisper.Envelope, error) { +) (whispertypes.Envelope, error) { params := whisper.MessageParams{ PoW: pow, Payload: payload, @@ -685,7 +686,11 @@ func makeEnvelop( if err != nil { return nil, err } - return message.Wrap(¶ms, now) + envelope, err := message.Wrap(¶ms, now) + if err != nil { + return nil, err + } + return gethbridge.NewGethEnvelopeWrapper(envelope), nil } // makeMessagesRequestPayload makes a specific payload for MailServer @@ -719,13 +724,13 @@ func createBloomFilter(r MessagesRequest) []byte { return topicsToBloom(r.Topics...) } - return whisper.TopicToBloom(r.Topic) + return whisper.TopicToBloom(whisper.TopicType(r.Topic)) } -func topicsToBloom(topics ...whisper.TopicType) []byte { +func topicsToBloom(topics ...whispertypes.TopicType) []byte { i := new(big.Int) for _, topic := range topics { - bloom := whisper.TopicToBloom(topic) + bloom := whispertypes.TopicToBloom(topic) i.Or(i, new(big.Int).SetBytes(bloom[:])) } diff --git a/services/shhext/api_test.go b/services/shhext/api_test.go index bffa9deec..9a4b5513a 100644 --- a/services/shhext/api_test.go +++ b/services/shhext/api_test.go @@ -7,10 +7,13 @@ import ( "testing" "time" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" + whisper "github.com/status-im/whisper/whisperv6" + "github.com/ethereum/go-ethereum/common" "github.com/status-im/status-go/mailserver" - whisper "github.com/status-im/whisper/whisperv6" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -100,26 +103,26 @@ func TestMakeMessagesRequestPayload(t *testing.T) { func TestTopicsToBloom(t *testing.T) { t1 := stringToTopic("t1") - b1 := whisper.TopicToBloom(t1) + b1 := whispertypes.TopicToBloom(t1) t2 := stringToTopic("t2") - b2 := whisper.TopicToBloom(t2) + b2 := whispertypes.TopicToBloom(t2) t3 := stringToTopic("t3") - b3 := whisper.TopicToBloom(t3) + b3 := whispertypes.TopicToBloom(t3) reqBloom := topicsToBloom(t1) - assert.True(t, whisper.BloomFilterMatch(reqBloom, b1)) - assert.False(t, whisper.BloomFilterMatch(reqBloom, b2)) - assert.False(t, whisper.BloomFilterMatch(reqBloom, b3)) + assert.True(t, whispertypes.BloomFilterMatch(reqBloom, b1)) + assert.False(t, whispertypes.BloomFilterMatch(reqBloom, b2)) + assert.False(t, whispertypes.BloomFilterMatch(reqBloom, b3)) reqBloom = topicsToBloom(t1, t2) - assert.True(t, whisper.BloomFilterMatch(reqBloom, b1)) - assert.True(t, whisper.BloomFilterMatch(reqBloom, b2)) - assert.False(t, whisper.BloomFilterMatch(reqBloom, b3)) + assert.True(t, whispertypes.BloomFilterMatch(reqBloom, b1)) + assert.True(t, whispertypes.BloomFilterMatch(reqBloom, b2)) + assert.False(t, whispertypes.BloomFilterMatch(reqBloom, b3)) reqBloom = topicsToBloom(t1, t2, t3) - assert.True(t, whisper.BloomFilterMatch(reqBloom, b1)) - assert.True(t, whisper.BloomFilterMatch(reqBloom, b2)) - assert.True(t, whisper.BloomFilterMatch(reqBloom, b3)) + assert.True(t, whispertypes.BloomFilterMatch(reqBloom, b1)) + assert.True(t, whispertypes.BloomFilterMatch(reqBloom, b2)) + assert.True(t, whispertypes.BloomFilterMatch(reqBloom, b3)) } func TestCreateBloomFilter(t *testing.T) { @@ -130,36 +133,36 @@ func TestCreateBloomFilter(t *testing.T) { bloom := createBloomFilter(req) assert.Equal(t, topicsToBloom(t1), bloom) - req = MessagesRequest{Topics: []whisper.TopicType{t1, t2}} + req = MessagesRequest{Topics: []whispertypes.TopicType{t1, t2}} bloom = createBloomFilter(req) assert.Equal(t, topicsToBloom(t1, t2), bloom) } -func stringToTopic(s string) whisper.TopicType { - return whisper.BytesToTopic([]byte(s)) +func stringToTopic(s string) whispertypes.TopicType { + return whispertypes.BytesToTopic([]byte(s)) } func TestCreateSyncMailRequest(t *testing.T) { testCases := []struct { Name string Req SyncMessagesRequest - Verify func(*testing.T, whisper.SyncMailRequest) + Verify func(*testing.T, whispertypes.SyncMailRequest) Error string }{ { Name: "no topics", Req: SyncMessagesRequest{}, - Verify: func(t *testing.T, r whisper.SyncMailRequest) { - require.Equal(t, whisper.MakeFullNodeBloom(), r.Bloom) + Verify: func(t *testing.T, r whispertypes.SyncMailRequest) { + require.Equal(t, whispertypes.MakeFullNodeBloom(), r.Bloom) }, }, { Name: "some topics", Req: SyncMessagesRequest{ - Topics: []whisper.TopicType{{0x01, 0xff, 0xff, 0xff}}, + Topics: []whispertypes.TopicType{{0x01, 0xff, 0xff, 0xff}}, }, - Verify: func(t *testing.T, r whisper.SyncMailRequest) { - expectedBloom := whisper.TopicToBloom(whisper.TopicType{0x01, 0xff, 0xff, 0xff}) + Verify: func(t *testing.T, r whispertypes.SyncMailRequest) { + expectedBloom := whispertypes.TopicToBloom(whispertypes.TopicType{0x01, 0xff, 0xff, 0xff}) require.Equal(t, expectedBloom, r.Bloom) }, }, @@ -168,7 +171,7 @@ func TestCreateSyncMailRequest(t *testing.T) { Req: SyncMessagesRequest{ Cursor: hex.EncodeToString([]byte{0x01, 0x02, 0x03}), }, - Verify: func(t *testing.T, r whisper.SyncMailRequest) { + Verify: func(t *testing.T, r whispertypes.SyncMailRequest) { require.Equal(t, []byte{0x01, 0x02, 0x03}, r.Cursor) }, }, @@ -223,9 +226,9 @@ func TestSyncMessagesErrors(t *testing.T) { func TestExpiredOrCompleted(t *testing.T) { timeout := time.Millisecond - events := make(chan whisper.EnvelopeEvent) + events := make(chan whispertypes.EnvelopeEvent) errors := make(chan error, 1) - hash := common.Hash{1} + hash := statusproto.Hash{1} go func() { _, err := waitForExpiredOrCompleted(hash, events, timeout) errors <- err diff --git a/services/shhext/dedup/cache.go b/services/shhext/dedup/cache.go index 30a79a039..aa80b08a9 100644 --- a/services/shhext/dedup/cache.go +++ b/services/shhext/dedup/cache.go @@ -4,7 +4,7 @@ import ( "time" "github.com/status-im/status-go/db" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/util" "golang.org/x/crypto/sha3" @@ -21,7 +21,7 @@ func newCache(db *leveldb.DB) *cache { return &cache{db, time.Now} } -func (d *cache) Has(filterID string, message *whisper.Message) (bool, error) { +func (d *cache) Has(filterID string, message *whispertypes.Message) (bool, error) { has, err := d.db.Has(d.KeyToday(filterID, message), nil) if err != nil { @@ -34,7 +34,7 @@ func (d *cache) Has(filterID string, message *whisper.Message) (bool, error) { return d.db.Has(d.keyYesterday(filterID, message), nil) } -func (d *cache) Put(filterID string, messages []*whisper.Message) error { +func (d *cache) Put(filterID string, messages []*whispertypes.Message) error { batch := leveldb.Batch{} for _, msg := range messages { @@ -89,11 +89,11 @@ func (d *cache) cleanOldEntries() error { return d.db.Write(&batch, nil) } -func (d *cache) keyYesterday(filterID string, message *whisper.Message) []byte { +func (d *cache) keyYesterday(filterID string, message *whispertypes.Message) []byte { return prefixedKey(d.yesterdayDateString(), filterID, message) } -func (d *cache) KeyToday(filterID string, message *whisper.Message) []byte { +func (d *cache) KeyToday(filterID string, message *whispertypes.Message) []byte { return prefixedKey(d.todayDateString(), filterID, message) } @@ -112,11 +112,11 @@ func dateString(t time.Time) string { return t.Format("20060102") } -func prefixedKey(date, filterID string, message *whisper.Message) []byte { +func prefixedKey(date, filterID string, message *whispertypes.Message) []byte { return db.Key(db.DeduplicatorCache, []byte(date), []byte(filterID), key(message)) } -func key(message *whisper.Message) []byte { +func key(message *whispertypes.Message) []byte { data := make([]byte, len(message.Payload)+len(message.Topic)) copy(data[:], message.Payload) copy(data[len(message.Payload):], message.Topic[:]) diff --git a/services/shhext/dedup/deduplicator.go b/services/shhext/dedup/deduplicator.go index 5f88c481e..4d707bef9 100644 --- a/services/shhext/dedup/deduplicator.go +++ b/services/shhext/dedup/deduplicator.go @@ -3,8 +3,8 @@ package dedup import ( "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/common/hexutil" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/syndtr/goleveldb/leveldb" ) @@ -21,21 +21,21 @@ type Deduplicator struct { } type Author struct { - PublicKey hexutil.Bytes `json:"publicKey"` - Alias string `json:"alias"` - Identicon string `json:"identicon"` + PublicKey statusproto.HexBytes `json:"publicKey"` + Alias string `json:"alias"` + Identicon string `json:"identicon"` } type Metadata struct { - DedupID []byte `json:"dedupId"` - EncryptionID hexutil.Bytes `json:"encryptionId"` - MessageID hexutil.Bytes `json:"messageId"` - Author Author `json:"author"` + DedupID []byte `json:"dedupId"` + EncryptionID statusproto.HexBytes `json:"encryptionId"` + MessageID statusproto.HexBytes `json:"messageId"` + Author Author `json:"author"` } type DeduplicateMessage struct { - Message *whisper.Message `json:"message"` - Metadata Metadata `json:"metadata"` + Message *whispertypes.Message `json:"message"` + Metadata Metadata `json:"metadata"` } // NewDeduplicator creates a new deduplicator diff --git a/services/shhext/dedup/utils_test.go b/services/shhext/dedup/utils_test.go index 64372d2f6..39c85f564 100644 --- a/services/shhext/dedup/utils_test.go +++ b/services/shhext/dedup/utils_test.go @@ -3,14 +3,14 @@ package dedup import ( "crypto/rand" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" ) -func generateMessages(count int) []*whisper.Message { - result := []*whisper.Message{} +func generateMessages(count int) []*whispertypes.Message { + result := []*whispertypes.Message{} for ; count > 0; count-- { content := mustGenerateRandomBytes() - result = append(result, &whisper.Message{Payload: content}) + result = append(result, &whispertypes.Message{Payload: content}) } return result } @@ -21,7 +21,7 @@ func generateDedupMessages(count int) []*DeduplicateMessage { content := mustGenerateRandomBytes() result = append(result, &DeduplicateMessage{ Metadata: Metadata{}, - Message: &whisper.Message{Payload: content}, + Message: &whispertypes.Message{Payload: content}, }) } return result diff --git a/services/shhext/history.go b/services/shhext/history.go index 430cde598..f545e6f7a 100644 --- a/services/shhext/history.go +++ b/services/shhext/history.go @@ -7,11 +7,11 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" "github.com/status-im/status-go/db" "github.com/status-im/status-go/mailserver" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" ) const ( @@ -36,7 +36,7 @@ type HistoryUpdateReactor struct { // UpdateFinishedRequest removes successfully finished request and updates every topic // attached to the request. -func (reactor *HistoryUpdateReactor) UpdateFinishedRequest(ctx Context, id common.Hash) error { +func (reactor *HistoryUpdateReactor) UpdateFinishedRequest(ctx Context, id statusproto.Hash) error { reactor.mu.Lock() defer reactor.mu.Unlock() req, err := ctx.HistoryStore().GetRequest(id) @@ -45,7 +45,7 @@ func (reactor *HistoryUpdateReactor) UpdateFinishedRequest(ctx Context, id commo } for i := range req.Histories() { th := &req.Histories()[i] - th.RequestID = common.Hash{} + th.RequestID = statusproto.Hash{} th.Current = th.End th.End = time.Time{} if err := th.Save(); err != nil { @@ -56,7 +56,7 @@ func (reactor *HistoryUpdateReactor) UpdateFinishedRequest(ctx Context, id commo } // UpdateTopicHistory updates Current timestamp for the TopicHistory with a given timestamp. -func (reactor *HistoryUpdateReactor) UpdateTopicHistory(ctx Context, topic whisper.TopicType, timestamp time.Time) error { +func (reactor *HistoryUpdateReactor) UpdateTopicHistory(ctx Context, topic whispertypes.TopicType, timestamp time.Time) error { reactor.mu.Lock() defer reactor.mu.Unlock() histories, err := ctx.HistoryStore().GetHistoriesByTopic(topic) @@ -87,7 +87,7 @@ func (reactor *HistoryUpdateReactor) UpdateTopicHistory(ctx Context, topic whisp // TopicRequest defines what user has to provide. type TopicRequest struct { - Topic whisper.TopicType + Topic whispertypes.TopicType Duration time.Duration } @@ -96,14 +96,14 @@ type TopicRequest struct { func (reactor *HistoryUpdateReactor) CreateRequests(ctx Context, topicRequests []TopicRequest) ([]db.HistoryRequest, error) { reactor.mu.Lock() defer reactor.mu.Unlock() - seen := map[whisper.TopicType]struct{}{} + seen := map[whispertypes.TopicType]struct{}{} for i := range topicRequests { if _, exist := seen[topicRequests[i].Topic]; exist { return nil, errors.New("only one duration per topic is allowed") } seen[topicRequests[i].Topic] = struct{}{} } - histories := map[whisper.TopicType]db.TopicHistory{} + histories := map[whispertypes.TopicType]db.TopicHistory{} for i := range topicRequests { th, err := ctx.HistoryStore().GetHistory(topicRequests[i].Topic, topicRequests[i].Duration) if err != nil { @@ -250,7 +250,7 @@ func CreateTopicOptionsFromRequest(req db.HistoryRequest) TopicOptions { return rst } -func mapToList(topics map[whisper.TopicType]db.TopicHistory) []db.TopicHistory { +func mapToList(topics map[whispertypes.TopicType]db.TopicHistory) []db.TopicHistory { rst := make([]db.TopicHistory, 0, len(topics)) for key := range topics { rst = append(rst, topics[key]) @@ -289,7 +289,7 @@ type Range struct { // TopicOption request for a single topic. type TopicOption struct { - Topic whisper.TopicType + Topic whispertypes.TopicType Range Range } @@ -298,7 +298,7 @@ type TopicOptions []TopicOption // ToBloomFilterOption creates bloom filter request from a list of topics. func (options TopicOptions) ToBloomFilterOption() BloomFilterOption { - topics := make([]whisper.TopicType, len(options)) + topics := make([]whispertypes.TopicType, len(options)) var start, end uint64 for i := range options { opt := options[i] @@ -318,8 +318,8 @@ func (options TopicOptions) ToBloomFilterOption() BloomFilterOption { } // Topics returns list of whisper TopicType attached to each TopicOption. -func (options TopicOptions) Topics() []whisper.TopicType { - rst := make([]whisper.TopicType, len(options)) +func (options TopicOptions) Topics() []whispertypes.TopicType { + rst := make([]whispertypes.TopicType, len(options)) for i := range options { rst[i] = options[i].Topic } diff --git a/services/shhext/history_test.go b/services/shhext/history_test.go index a75537a93..5d0233256 100644 --- a/services/shhext/history_test.go +++ b/services/shhext/history_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" "github.com/status-im/status-go/db" "github.com/status-im/status-go/mailserver" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -51,7 +51,7 @@ func TestRenewRequest(t *testing.T) { func TestCreateTopicOptionsFromRequest(t *testing.T) { req := db.HistoryRequest{} - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} now := time.Now() req.AddHistory(db.TopicHistory{Topic: topic, Current: now, End: now}) options := CreateTopicOptionsFromRequest(req) @@ -65,8 +65,8 @@ func TestCreateTopicOptionsFromRequest(t *testing.T) { func TestTopicOptionsToBloom(t *testing.T) { options := TopicOptions{ - {Topic: whisper.TopicType{1}, Range: Range{Start: 1, End: 10}}, - {Topic: whisper.TopicType{2}, Range: Range{Start: 3, End: 12}}, + {Topic: whispertypes.TopicType{1}, Range: Range{Start: 1, End: 10}}, + {Topic: whispertypes.TopicType{2}, Range: Range{Start: 3, End: 12}}, } bloom := options.ToBloomFilterOption() require.Equal(t, uint64(3), bloom.Range.Start, "Start must be the latest Start across all options") @@ -105,9 +105,9 @@ func TestCreateRequestsEmptyState(t *testing.T) { ctx := newTestContext(t) reactor := NewHistoryUpdateReactor() requests, err := reactor.CreateRequests(ctx, []TopicRequest{ - {Topic: whisper.TopicType{1}, Duration: time.Hour}, - {Topic: whisper.TopicType{2}, Duration: time.Hour}, - {Topic: whisper.TopicType{3}, Duration: 10 * time.Hour}, + {Topic: whispertypes.TopicType{1}, Duration: time.Hour}, + {Topic: whispertypes.TopicType{2}, Duration: time.Hour}, + {Topic: whispertypes.TopicType{3}, Duration: 10 * time.Hour}, }) require.NoError(t, err) require.Len(t, requests, 2) @@ -128,15 +128,15 @@ func TestCreateRequestsWithExistingRequest(t *testing.T) { ctx := newTestContext(t) store := ctx.HistoryStore() req := store.NewRequest() - req.ID = common.Hash{1} - th := store.NewHistory(whisper.TopicType{1}, time.Hour) + req.ID = statusproto.Hash{1} + th := store.NewHistory(whispertypes.TopicType{1}, time.Hour) req.AddHistory(th) require.NoError(t, req.Save()) reactor := NewHistoryUpdateReactor() requests, err := reactor.CreateRequests(ctx, []TopicRequest{ - {Topic: whisper.TopicType{1}, Duration: time.Hour}, - {Topic: whisper.TopicType{2}, Duration: time.Hour}, - {Topic: whisper.TopicType{3}, Duration: time.Hour}, + {Topic: whispertypes.TopicType{1}, Duration: time.Hour}, + {Topic: whispertypes.TopicType{2}, Duration: time.Hour}, + {Topic: whispertypes.TopicType{3}, Duration: time.Hour}, }) require.NoError(t, err) require.Len(t, requests, 2) @@ -157,13 +157,13 @@ func TestCreateMultiRequestsWithSameTopic(t *testing.T) { ctx := newTestContext(t) store := ctx.HistoryStore() reactor := NewHistoryUpdateReactor() - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} requests, err := reactor.CreateRequests(ctx, []TopicRequest{ {Topic: topic, Duration: time.Hour}, }) require.NoError(t, err) require.Len(t, requests, 1) - requests[0].ID = common.Hash{1} + requests[0].ID = statusproto.Hash{1} require.NoError(t, requests[0].Save()) // duration changed. request wasn't finished @@ -175,7 +175,7 @@ func TestCreateMultiRequestsWithSameTopic(t *testing.T) { longest := 0 for i := range requests { r := &requests[i] - r.ID = common.Hash{byte(i)} + r.ID = statusproto.Hash{byte(i)} require.NoError(t, r.Save()) require.Len(t, r.Histories(), 1) if r.Histories()[0].Duration == 10*time.Hour { @@ -203,11 +203,11 @@ func TestRequestFinishedUpdate(t *testing.T) { ctx := newTestContext(t) store := ctx.HistoryStore() req := store.NewRequest() - req.ID = common.Hash{1} + req.ID = statusproto.Hash{1} now := ctx.Time() - thOne := store.NewHistory(whisper.TopicType{1}, time.Hour) + thOne := store.NewHistory(whispertypes.TopicType{1}, time.Hour) thOne.End = now - thTwo := store.NewHistory(whisper.TopicType{2}, time.Hour) + thTwo := store.NewHistory(whispertypes.TopicType{2}, time.Hour) thTwo.End = now req.AddHistory(thOne) req.AddHistory(thTwo) @@ -228,12 +228,12 @@ func TestRequestFinishedUpdate(t *testing.T) { func TestTopicHistoryUpdate(t *testing.T) { ctx := newTestContext(t) store := ctx.HistoryStore() - reqID := common.Hash{1} + reqID := statusproto.Hash{1} request := store.NewRequest() request.ID = reqID now := time.Now() require.NoError(t, request.Save()) - th := store.NewHistory(whisper.TopicType{1}, time.Hour) + th := store.NewHistory(whispertypes.TopicType{1}, time.Hour) th.RequestID = request.ID th.End = now require.NoError(t, th.Save()) @@ -251,12 +251,12 @@ func TestTopicHistoryUpdate(t *testing.T) { func TestGroupHistoriesByRequestTimestamp(t *testing.T) { requests := GroupHistoriesByRequestTimespan(createInMemStore(t), []db.TopicHistory{ - {Topic: whisper.TopicType{1}, Duration: time.Hour}, - {Topic: whisper.TopicType{2}, Duration: time.Hour}, - {Topic: whisper.TopicType{3}, Duration: 2 * time.Hour}, - {Topic: whisper.TopicType{4}, Duration: 2 * time.Hour}, - {Topic: whisper.TopicType{5}, Duration: 3 * time.Hour}, - {Topic: whisper.TopicType{6}, Duration: 3 * time.Hour}, + {Topic: whispertypes.TopicType{1}, Duration: time.Hour}, + {Topic: whispertypes.TopicType{2}, Duration: time.Hour}, + {Topic: whispertypes.TopicType{3}, Duration: 2 * time.Hour}, + {Topic: whispertypes.TopicType{4}, Duration: 2 * time.Hour}, + {Topic: whispertypes.TopicType{5}, Duration: 3 * time.Hour}, + {Topic: whispertypes.TopicType{6}, Duration: 3 * time.Hour}, }) require.Len(t, requests, 3) for _, req := range requests { @@ -267,7 +267,7 @@ func TestGroupHistoriesByRequestTimestamp(t *testing.T) { // initial creation of the history index. no other histories in store func TestAdjustHistoryWithNoOtherHistories(t *testing.T) { store := createInMemStore(t) - th := store.NewHistory(whisper.TopicType{1}, time.Hour) + th := store.NewHistory(whispertypes.TopicType{1}, time.Hour) adjusted, err := adjustRequestedHistories(store, []db.TopicHistory{th}) require.NoError(t, err) require.Len(t, adjusted, 1) @@ -281,7 +281,7 @@ func TestAdjustHistoryWithNoOtherHistories(t *testing.T) { // that covers all of them e.g. {Duration: 4h} func TestAdjustHistoryWithExistingLowerRanges(t *testing.T) { store := createInMemStore(t) - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} histories := make([]db.TopicHistory, 3) i := 0 for i = range histories { @@ -309,7 +309,7 @@ func TestAdjustHistoryWithExistingLowerRanges(t *testing.T) { // We see that there is no reason to keep all indexes and we can squash them. func TestAdjustHistoriesWithExistingCoveredLowerRanges(t *testing.T) { store := createInMemStore(t) - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} histories := make([]db.TopicHistory, 3) i := 0 now := time.Now() @@ -332,7 +332,7 @@ func TestAdjustHistoriesWithExistingCoveredLowerRanges(t *testing.T) { func TestAdjustHistoryReplaceTopicWithHigherDuration(t *testing.T) { store := createInMemStore(t) - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} hour := store.NewHistory(topic, time.Hour) require.NoError(t, hour.Save()) minute := store.NewHistory(topic, time.Minute) @@ -346,9 +346,9 @@ func TestAdjustHistoryReplaceTopicWithHigherDuration(t *testing.T) { // it will be discarded and we will use existing index func TestAdjustHistoryRemoveTopicIfPendingWithHigherDuration(t *testing.T) { store := createInMemStore(t) - topic := whisper.TopicType{1} + topic := whispertypes.TopicType{1} hour := store.NewHistory(topic, time.Hour) - hour.RequestID = common.Hash{1} + hour.RequestID = statusproto.Hash{1} require.NoError(t, hour.Save()) minute := store.NewHistory(topic, time.Minute) adjusted, err := adjustRequestedHistories(store, []db.TopicHistory{minute}) diff --git a/services/shhext/mailrequests.go b/services/shhext/mailrequests.go index 3739223ae..3175fc22e 100644 --- a/services/shhext/mailrequests.go +++ b/services/shhext/mailrequests.go @@ -3,9 +3,9 @@ package shhext import ( "sync" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" ) // EnvelopeState in local tracker @@ -24,11 +24,11 @@ const ( // MailRequestMonitor is responsible for monitoring history request to mailservers. type MailRequestMonitor struct { - w *whisper.Whisper + w whispertypes.Whisper handler EnvelopeEventsHandler mu sync.Mutex - cache map[common.Hash]EnvelopeState + cache map[statusproto.Hash]EnvelopeState requestsRegistry *RequestsRegistry @@ -52,7 +52,7 @@ func (m *MailRequestMonitor) Stop() { m.wg.Wait() } -func (m *MailRequestMonitor) GetState(hash common.Hash) EnvelopeState { +func (m *MailRequestMonitor) GetState(hash statusproto.Hash) EnvelopeState { m.mu.Lock() defer m.mu.Unlock() state, exist := m.cache[hash] @@ -64,7 +64,7 @@ func (m *MailRequestMonitor) GetState(hash common.Hash) EnvelopeState { // handleEnvelopeEvents processes whisper envelope events func (m *MailRequestMonitor) handleEnvelopeEvents() { - events := make(chan whisper.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper + events := make(chan whispertypes.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper sub := m.w.SubscribeEnvelopeEvents(events) defer sub.Unsubscribe() for { @@ -79,11 +79,11 @@ func (m *MailRequestMonitor) handleEnvelopeEvents() { // handleEvent based on type of the event either triggers // confirmation handler or removes hash from MailRequestMonitor -func (m *MailRequestMonitor) handleEvent(event whisper.EnvelopeEvent) { - handlers := map[whisper.EventType]func(whisper.EnvelopeEvent){ - whisper.EventMailServerRequestSent: m.handleRequestSent, - whisper.EventMailServerRequestCompleted: m.handleEventMailServerRequestCompleted, - whisper.EventMailServerRequestExpired: m.handleEventMailServerRequestExpired, +func (m *MailRequestMonitor) handleEvent(event whispertypes.EnvelopeEvent) { + handlers := map[whispertypes.EventType]func(whispertypes.EnvelopeEvent){ + whispertypes.EventMailServerRequestSent: m.handleRequestSent, + whispertypes.EventMailServerRequestCompleted: m.handleEventMailServerRequestCompleted, + whispertypes.EventMailServerRequestExpired: m.handleEventMailServerRequestExpired, } if handler, ok := handlers[event.Event]; ok { @@ -91,13 +91,13 @@ func (m *MailRequestMonitor) handleEvent(event whisper.EnvelopeEvent) { } } -func (m *MailRequestMonitor) handleRequestSent(event whisper.EnvelopeEvent) { +func (m *MailRequestMonitor) handleRequestSent(event whispertypes.EnvelopeEvent) { m.mu.Lock() defer m.mu.Unlock() m.cache[event.Hash] = MailServerRequestSent } -func (m *MailRequestMonitor) handleEventMailServerRequestCompleted(event whisper.EnvelopeEvent) { +func (m *MailRequestMonitor) handleEventMailServerRequestCompleted(event whispertypes.EnvelopeEvent) { m.mu.Lock() defer m.mu.Unlock() m.requestsRegistry.Unregister(event.Hash) @@ -108,13 +108,13 @@ func (m *MailRequestMonitor) handleEventMailServerRequestCompleted(event whisper log.Debug("mailserver response received", "hash", event.Hash) delete(m.cache, event.Hash) if m.handler != nil { - if resp, ok := event.Data.(*whisper.MailServerResponse); ok { + if resp, ok := event.Data.(*whispertypes.MailServerResponse); ok { m.handler.MailServerRequestCompleted(event.Hash, resp.LastEnvelopeHash, resp.Cursor, resp.Error) } } } -func (m *MailRequestMonitor) handleEventMailServerRequestExpired(event whisper.EnvelopeEvent) { +func (m *MailRequestMonitor) handleEventMailServerRequestExpired(event whispertypes.EnvelopeEvent) { m.mu.Lock() defer m.mu.Unlock() m.requestsRegistry.Unregister(event.Hash) diff --git a/services/shhext/mailrequests_test.go b/services/shhext/mailrequests_test.go index 93828fe0a..372462427 100644 --- a/services/shhext/mailrequests_test.go +++ b/services/shhext/mailrequests_test.go @@ -5,13 +5,13 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/stretchr/testify/suite" ) var ( - testHash = common.Hash{0x01} + testHash = statusproto.Hash{0x01} ) func TestMailRequestMonitorSuite(t *testing.T) { @@ -26,7 +26,7 @@ type MailRequestMonitorSuite struct { func (s *MailRequestMonitorSuite) SetupTest() { s.monitor = &MailRequestMonitor{ - cache: map[common.Hash]EnvelopeState{}, + cache: map[statusproto.Hash]EnvelopeState{}, requestsRegistry: NewRequestsRegistry(0), } } @@ -35,10 +35,10 @@ func (s *MailRequestMonitorSuite) TestRequestCompleted() { mock := newHandlerMock(1) s.monitor.handler = mock s.monitor.cache[testHash] = MailServerRequestSent - s.monitor.handleEvent(whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestCompleted, + s.monitor.handleEvent(whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestCompleted, Hash: testHash, - Data: &whisper.MailServerResponse{}, + Data: &whispertypes.MailServerResponse{}, }) select { case requestID := <-mock.requestsCompleted: @@ -53,10 +53,10 @@ func (s *MailRequestMonitorSuite) TestRequestFailed() { mock := newHandlerMock(1) s.monitor.handler = mock s.monitor.cache[testHash] = MailServerRequestSent - s.monitor.handleEvent(whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestCompleted, + s.monitor.handleEvent(whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestCompleted, Hash: testHash, - Data: &whisper.MailServerResponse{Error: errors.New("test error")}, + Data: &whispertypes.MailServerResponse{Error: errors.New("test error")}, }) select { case requestID := <-mock.requestsFailed: @@ -71,8 +71,8 @@ func (s *MailRequestMonitorSuite) TestRequestExpiration() { mock := newHandlerMock(1) s.monitor.handler = mock s.monitor.cache[testHash] = MailServerRequestSent - s.monitor.handleEvent(whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestExpired, + s.monitor.handleEvent(whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestExpired, Hash: testHash, }) select { diff --git a/services/shhext/mailservers/cache.go b/services/shhext/mailservers/cache.go index 3fd314e97..06af16ef3 100644 --- a/services/shhext/mailservers/cache.go +++ b/services/shhext/mailservers/cache.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/status-im/status-go/db" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/util" @@ -67,8 +68,8 @@ func (c *Cache) Replace(nodes []*enode.Node) error { if err != nil { return err } - if _, exist := newNodes[record.ID()]; exist { - delete(newNodes, record.ID()) + if _, exist := newNodes[whispertypes.EnodeID(record.ID())]; exist { + delete(newNodes, whispertypes.EnodeID(record.ID())) } else { batch.Delete(iter.Key()) } @@ -124,10 +125,10 @@ func unmarshalKeyValue(key, value []byte) (record PeerRecord, err error) { return record, err } -func nodesToMap(nodes []*enode.Node) map[enode.ID]*enode.Node { - rst := map[enode.ID]*enode.Node{} +func nodesToMap(nodes []*enode.Node) map[whispertypes.EnodeID]*enode.Node { + rst := map[whispertypes.EnodeID]*enode.Node{} for _, n := range nodes { - rst[n.ID()] = n + rst[whispertypes.EnodeID(n.ID())] = n } return rst } diff --git a/services/shhext/mailservers/connmanager.go b/services/shhext/mailservers/connmanager.go index 84c58ff4a..807e65bfe 100644 --- a/services/shhext/mailservers/connmanager.go +++ b/services/shhext/mailservers/connmanager.go @@ -4,12 +4,12 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" ) const ( @@ -28,9 +28,9 @@ type PeerEventsSubscriber interface { SubscribeEvents(chan *p2p.PeerEvent) event.Subscription } -// EnvelopeEventSubscbriber interface to subscribe for whisper.EnvelopeEvent's. -type EnvelopeEventSubscbriber interface { - SubscribeEnvelopeEvents(chan<- whisper.EnvelopeEvent) event.Subscription +// EnvelopeEventSubscriber interface to subscribe for whispertypes.EnvelopeEvent's. +type EnvelopeEventSubscriber interface { + SubscribeEnvelopeEvents(chan<- whispertypes.EnvelopeEvent) whispertypes.Subscription } type p2pServer interface { @@ -39,7 +39,7 @@ type p2pServer interface { } // NewConnectionManager creates an instance of ConnectionManager. -func NewConnectionManager(server p2pServer, whisper EnvelopeEventSubscbriber, target, maxFailures int, timeout time.Duration) *ConnectionManager { +func NewConnectionManager(server p2pServer, whisper EnvelopeEventSubscriber, target, maxFailures int, timeout time.Duration) *ConnectionManager { return &ConnectionManager{ server: server, whisper: whisper, @@ -56,7 +56,7 @@ type ConnectionManager struct { quit chan struct{} server p2pServer - whisper EnvelopeEventSubscbriber + whisper EnvelopeEventSubscriber notifications chan []*enode.Node connectedTarget int @@ -85,10 +85,10 @@ func (ps *ConnectionManager) Start() { state := newInternalState(ps.server, ps.connectedTarget, ps.timeoutWaitAdded) events := make(chan *p2p.PeerEvent, peerEventsBuffer) sub := ps.server.SubscribeEvents(events) - whisperEvents := make(chan whisper.EnvelopeEvent, whisperEventsBuffer) + whisperEvents := make(chan whispertypes.EnvelopeEvent, whisperEventsBuffer) whisperSub := ps.whisper.SubscribeEnvelopeEvents(whisperEvents) - requests := map[common.Hash]struct{}{} - failuresPerServer := map[enode.ID]int{} + requests := map[statusproto.Hash]struct{}{} + failuresPerServer := map[whispertypes.EnodeID]int{} defer sub.Unsubscribe() defer whisperSub.Unsubscribe() @@ -110,13 +110,13 @@ func (ps *ConnectionManager) Start() { case ev := <-whisperEvents: // TODO treat failed requests the same way as expired switch ev.Event { - case whisper.EventMailServerRequestSent: + case whispertypes.EventMailServerRequestSent: requests[ev.Hash] = struct{}{} - case whisper.EventMailServerRequestCompleted: + case whispertypes.EventMailServerRequestCompleted: // reset failures count on first success failuresPerServer[ev.Peer] = 0 delete(requests, ev.Hash) - case whisper.EventMailServerRequestExpired: + case whispertypes.EventMailServerRequestExpired: _, exist := requests[ev.Hash] if !exist { continue @@ -148,9 +148,9 @@ func (ps *ConnectionManager) Stop() { } func (state *internalState) processReplacement(newNodes []*enode.Node, events <-chan *p2p.PeerEvent) { - replacement := map[enode.ID]*enode.Node{} + replacement := map[whispertypes.EnodeID]*enode.Node{} for _, n := range newNodes { - replacement[n.ID()] = n + replacement[whispertypes.EnodeID(n.ID())] = n } state.replaceNodes(replacement) if state.ReachedTarget() { @@ -170,8 +170,8 @@ func newInternalState(srv PeerAdderRemover, target int, timeout time.Duration) * return &internalState{ options: options{target: target, timeout: timeout}, srv: srv, - connected: map[enode.ID]struct{}{}, - currentNodes: map[enode.ID]*enode.Node{}, + connected: map[whispertypes.EnodeID]struct{}{}, + currentNodes: map[whispertypes.EnodeID]*enode.Node{}, } } @@ -184,15 +184,15 @@ type internalState struct { options srv PeerAdderRemover - connected map[enode.ID]struct{} - currentNodes map[enode.ID]*enode.Node + connected map[whispertypes.EnodeID]struct{} + currentNodes map[whispertypes.EnodeID]*enode.Node } func (state *internalState) ReachedTarget() bool { return len(state.connected) >= state.target } -func (state *internalState) replaceNodes(new map[enode.ID]*enode.Node) { +func (state *internalState) replaceNodes(new map[whispertypes.EnodeID]*enode.Node) { for nid, n := range state.currentNodes { if _, exist := new[nid]; !exist { delete(state.connected, nid) @@ -207,7 +207,7 @@ func (state *internalState) replaceNodes(new map[enode.ID]*enode.Node) { state.currentNodes = new } -func (state *internalState) nodeAdded(peer enode.ID) { +func (state *internalState) nodeAdded(peer whispertypes.EnodeID) { n, exist := state.currentNodes[peer] if !exist { return @@ -215,11 +215,11 @@ func (state *internalState) nodeAdded(peer enode.ID) { if state.ReachedTarget() { state.srv.RemovePeer(n) } else { - state.connected[n.ID()] = struct{}{} + state.connected[whispertypes.EnodeID(n.ID())] = struct{}{} } } -func (state *internalState) nodeDisconnected(peer enode.ID) { +func (state *internalState) nodeDisconnected(peer whispertypes.EnodeID) { n, exist := state.currentNodes[peer] // unrelated event if !exist { return @@ -248,10 +248,10 @@ func processPeerEvent(state *internalState, ev *p2p.PeerEvent) { switch ev.Type { case p2p.PeerEventTypeAdd: log.Debug("connected to a mailserver", "address", ev.Peer) - state.nodeAdded(ev.Peer) + state.nodeAdded(whispertypes.EnodeID(ev.Peer)) case p2p.PeerEventTypeDrop: log.Debug("mailserver disconnected", "address", ev.Peer) - state.nodeDisconnected(ev.Peer) + state.nodeDisconnected(whispertypes.EnodeID(ev.Peer)) } } diff --git a/services/shhext/mailservers/connmanager_test.go b/services/shhext/mailservers/connmanager_test.go index 64d959a6f..ddba091bc 100644 --- a/services/shhext/mailservers/connmanager_test.go +++ b/services/shhext/mailservers/connmanager_test.go @@ -6,25 +6,25 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/status-im/status-go/t/utils" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) type fakePeerEvents struct { mu sync.Mutex - nodes map[enode.ID]struct{} + nodes map[whispertypes.EnodeID]struct{} input chan *p2p.PeerEvent } -func (f *fakePeerEvents) Nodes() []enode.ID { +func (f *fakePeerEvents) Nodes() []whispertypes.EnodeID { f.mu.Lock() - rst := make([]enode.ID, 0, len(f.nodes)) + rst := make([]whispertypes.EnodeID, 0, len(f.nodes)) for n := range f.nodes { rst = append(rst, n) } @@ -34,7 +34,7 @@ func (f *fakePeerEvents) Nodes() []enode.ID { func (f *fakePeerEvents) AddPeer(node *enode.Node) { f.mu.Lock() - f.nodes[node.ID()] = struct{}{} + f.nodes[whispertypes.EnodeID(node.ID())] = struct{}{} f.mu.Unlock() if f.input == nil { return @@ -47,7 +47,7 @@ func (f *fakePeerEvents) AddPeer(node *enode.Node) { func (f *fakePeerEvents) RemovePeer(node *enode.Node) { f.mu.Lock() - delete(f.nodes, node.ID()) + delete(f.nodes, whispertypes.EnodeID(node.ID())) f.mu.Unlock() if f.input == nil { return @@ -59,7 +59,7 @@ func (f *fakePeerEvents) RemovePeer(node *enode.Node) { } func newFakePeerAdderRemover() *fakePeerEvents { - return &fakePeerEvents{nodes: map[enode.ID]struct{}{}} + return &fakePeerEvents{nodes: map[whispertypes.EnodeID]struct{}{}} } func (f *fakePeerEvents) SubscribeEvents(output chan *p2p.PeerEvent) event.Subscription { @@ -83,10 +83,10 @@ func newFakeServer() *fakePeerEvents { } type fakeEnvelopeEvents struct { - input chan whisper.EnvelopeEvent + input chan whispertypes.EnvelopeEvent } -func (f *fakeEnvelopeEvents) SubscribeEnvelopeEvents(output chan<- whisper.EnvelopeEvent) event.Subscription { +func (f *fakeEnvelopeEvents) SubscribeEnvelopeEvents(output chan<- whispertypes.EnvelopeEvent) whispertypes.Subscription { return event.NewSubscription(func(quit <-chan struct{}) error { for { select { @@ -102,7 +102,7 @@ func (f *fakeEnvelopeEvents) SubscribeEnvelopeEvents(output chan<- whisper.Envel func newFakeEnvelopesEvents() *fakeEnvelopeEvents { return &fakeEnvelopeEvents{ - input: make(chan whisper.EnvelopeEvent), + input: make(chan whispertypes.EnvelopeEvent), } } @@ -114,13 +114,13 @@ func fillWithRandomNodes(t *testing.T, nodes []*enode.Node) { } } -func getMapWithRandomNodes(t *testing.T, n int) map[enode.ID]*enode.Node { +func getMapWithRandomNodes(t *testing.T, n int) map[whispertypes.EnodeID]*enode.Node { nodes := make([]*enode.Node, n) fillWithRandomNodes(t, nodes) return nodesToMap(nodes) } -func mergeOldIntoNew(old, new map[enode.ID]*enode.Node) { +func mergeOldIntoNew(old, new map[whispertypes.EnodeID]*enode.Node) { for n := range old { new[n] = old[n] } @@ -129,8 +129,8 @@ func mergeOldIntoNew(old, new map[enode.ID]*enode.Node) { func TestReplaceNodes(t *testing.T) { type testCase struct { description string - old map[enode.ID]*enode.Node - new map[enode.ID]*enode.Node + old map[whispertypes.EnodeID]*enode.Node + new map[whispertypes.EnodeID]*enode.Node target int } for _, tc := range []testCase{ @@ -183,7 +183,7 @@ func TestPartialReplaceNodesAboveTarget(t *testing.T) { new := getMapWithRandomNodes(t, 2) state := newInternalState(peers, 1, 0) state.replaceNodes(old) - state.nodeAdded(initial.ID()) + state.nodeAdded(whispertypes.EnodeID(initial.ID())) mergeOldIntoNew(old, new) state.replaceNodes(new) require.Len(t, peers.nodes, 1) @@ -209,7 +209,7 @@ func TestConnectionManagerAddDrop(t *testing.T) { if len(nodes) != target { return fmt.Errorf("unexpected number of connected servers: %d", len(nodes)) } - initial = nodes[0] + initial = enode.ID(nodes[0]) return nil }, time.Second, 100*time.Millisecond)) // Send an event that peer was dropped. @@ -224,7 +224,7 @@ func TestConnectionManagerAddDrop(t *testing.T) { if len(nodes) != target { return fmt.Errorf("unexpected number of connected servers: %d", len(nodes)) } - if nodes[0] == initial { + if enode.ID(nodes[0]) == initial { return fmt.Errorf("connected node wasn't changed from %s", initial) } return nil @@ -250,7 +250,7 @@ func TestConnectionManagerReplace(t *testing.T) { if len(connected) != target { return fmt.Errorf("unexpected number of connected servers: %d", len(connected)) } - if nodes[0].ID() != connected[0] { + if whispertypes.EnodeID(nodes[0].ID()) != connected[0] { return fmt.Errorf("connected with a wrong peer. expected %s, got %s", nodes[0].ID(), connected[0]) } return nil @@ -263,7 +263,7 @@ func TestConnectionManagerReplace(t *testing.T) { if len(connected) != target { return fmt.Errorf("unexpected number of connected servers: %d", len(connected)) } - switch connected[0] { + switch enode.ID(connected[0]) { case nodes[1].ID(): case nodes[2].ID(): default: @@ -273,7 +273,7 @@ func TestConnectionManagerReplace(t *testing.T) { }, time.Second, 100*time.Millisecond)) } -func setupTestConnectionAfterExpiry(t *testing.T, server *fakePeerEvents, whisperMock *fakeEnvelopeEvents, target, maxFailures int, hash common.Hash) (*ConnectionManager, enode.ID) { +func setupTestConnectionAfterExpiry(t *testing.T, server *fakePeerEvents, whisperMock *fakeEnvelopeEvents, target, maxFailures int, hash statusproto.Hash) (*ConnectionManager, whispertypes.EnodeID) { connmanager := NewConnectionManager(server, whisperMock, target, maxFailures, 0) connmanager.Start() nodes := []*enode.Node{} @@ -282,7 +282,7 @@ func setupTestConnectionAfterExpiry(t *testing.T, server *fakePeerEvents, whispe } // Send two random nodes to connection manager. connmanager.Notify(nodes) - var initial enode.ID + var initial whispertypes.EnodeID // Wait until connection manager establishes connection with one node. require.NoError(t, utils.Eventually(func() error { nodes := server.Nodes() @@ -294,8 +294,8 @@ func setupTestConnectionAfterExpiry(t *testing.T, server *fakePeerEvents, whispe }, time.Second, 100*time.Millisecond)) // Send event that history request for connected peer was sent. select { - case whisperMock.input <- whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestSent, Peer: initial, Hash: hash}: + case whisperMock.input <- whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestSent, Peer: initial, Hash: hash}: case <-time.After(time.Second): require.FailNow(t, "can't send a 'sent' event") } @@ -307,14 +307,14 @@ func TestConnectionChangedAfterExpiry(t *testing.T) { whisperMock := newFakeEnvelopesEvents() target := 1 maxFailures := 1 - hash := common.Hash{1} + hash := statusproto.Hash{1} connmanager, initial := setupTestConnectionAfterExpiry(t, server, whisperMock, target, maxFailures, hash) defer connmanager.Stop() // And eventually expired. select { - case whisperMock.input <- whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestExpired, Peer: initial, Hash: hash}: + case whisperMock.input <- whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestExpired, Peer: initial, Hash: hash}: case <-time.After(time.Second): require.FailNow(t, "can't send an 'expiry' event") } @@ -335,14 +335,14 @@ func TestConnectionChangedAfterSecondExpiry(t *testing.T) { whisperMock := newFakeEnvelopesEvents() target := 1 maxFailures := 2 - hash := common.Hash{1} + hash := statusproto.Hash{1} connmanager, initial := setupTestConnectionAfterExpiry(t, server, whisperMock, target, maxFailures, hash) defer connmanager.Stop() // First expired is sent. Nothing should happen. select { - case whisperMock.input <- whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestExpired, Peer: initial, Hash: hash}: + case whisperMock.input <- whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestExpired, Peer: initial, Hash: hash}: case <-time.After(time.Second): require.FailNow(t, "can't send an 'expiry' event") } @@ -361,8 +361,8 @@ func TestConnectionChangedAfterSecondExpiry(t *testing.T) { // second expiry event select { - case whisperMock.input <- whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestExpired, Peer: initial, Hash: hash}: + case whisperMock.input <- whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestExpired, Peer: initial, Hash: hash}: case <-time.After(time.Second): require.FailNow(t, "can't send an 'expiry' event") } diff --git a/services/shhext/mailservers/connmonitor.go b/services/shhext/mailservers/connmonitor.go index 3f9612f11..bcb322d82 100644 --- a/services/shhext/mailservers/connmonitor.go +++ b/services/shhext/mailservers/connmonitor.go @@ -5,12 +5,11 @@ import ( "time" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/p2p/enode" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" ) // NewLastUsedConnectionMonitor returns pointer to the instance of LastUsedConnectionMonitor. -func NewLastUsedConnectionMonitor(ps *PeerStore, cache *Cache, whisper EnvelopeEventSubscbriber) *LastUsedConnectionMonitor { +func NewLastUsedConnectionMonitor(ps *PeerStore, cache *Cache, whisper EnvelopeEventSubscriber) *LastUsedConnectionMonitor { return &LastUsedConnectionMonitor{ ps: ps, cache: cache, @@ -23,7 +22,7 @@ type LastUsedConnectionMonitor struct { ps *PeerStore cache *Cache - whisper EnvelopeEventSubscbriber + whisper EnvelopeEventSubscriber quit chan struct{} wg sync.WaitGroup @@ -34,7 +33,7 @@ func (mon *LastUsedConnectionMonitor) Start() { mon.quit = make(chan struct{}) mon.wg.Add(1) go func() { - events := make(chan whisper.EnvelopeEvent, whisperEventsBuffer) + events := make(chan whispertypes.EnvelopeEvent, whisperEventsBuffer) sub := mon.whisper.SubscribeEnvelopeEvents(events) defer sub.Unsubscribe() defer mon.wg.Done() @@ -50,7 +49,7 @@ func (mon *LastUsedConnectionMonitor) Start() { if node == nil { continue } - if ev.Event == whisper.EventMailServerRequestCompleted { + if ev.Event == whispertypes.EventMailServerRequestCompleted { err := mon.updateRecord(ev.Peer) if err != nil { log.Error("unable to update storage", "peer", ev.Peer, "error", err) @@ -61,7 +60,7 @@ func (mon *LastUsedConnectionMonitor) Start() { }() } -func (mon *LastUsedConnectionMonitor) updateRecord(nodeID enode.ID) error { +func (mon *LastUsedConnectionMonitor) updateRecord(nodeID whispertypes.EnodeID) error { node := mon.ps.Get(nodeID) if node == nil { return nil diff --git a/services/shhext/mailservers/connmonitor_test.go b/services/shhext/mailservers/connmonitor_test.go index 3fa640f75..80326d503 100644 --- a/services/shhext/mailservers/connmonitor_test.go +++ b/services/shhext/mailservers/connmonitor_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/status-im/status-go/t/utils" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" "github.com/stretchr/testify/require" ) @@ -25,8 +25,8 @@ func TestUsedConnectionPersisted(t *testing.T) { // Send a confirmation that we received history from one of the peers. select { - case whisperMock.input <- whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestCompleted, Peer: nodes[0].ID()}: + case whisperMock.input <- whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestCompleted, Peer: whispertypes.EnodeID(nodes[0].ID())}: case <-time.After(time.Second): require.FailNow(t, "can't send a 'completed' event") } @@ -47,15 +47,15 @@ func TestUsedConnectionPersisted(t *testing.T) { } } if !used { - return fmt.Errorf("record %s is not marked as used", nodes[0].ID()) + return fmt.Errorf("record %s is not marked as used", whispertypes.EnodeID(nodes[0].ID())) } return nil }, time.Second, 100*time.Millisecond)) // Use different peer, first will be marked as unused. select { - case whisperMock.input <- whisper.EnvelopeEvent{ - Event: whisper.EventMailServerRequestCompleted, Peer: nodes[1].ID()}: + case whisperMock.input <- whispertypes.EnvelopeEvent{ + Event: whispertypes.EventMailServerRequestCompleted, Peer: whispertypes.EnodeID(nodes[1].ID())}: case <-time.After(time.Second): require.FailNow(t, "can't send a 'completed' event") } diff --git a/services/shhext/mailservers/peerstore.go b/services/shhext/mailservers/peerstore.go index fdfde7ef3..a240fd54d 100644 --- a/services/shhext/mailservers/peerstore.go +++ b/services/shhext/mailservers/peerstore.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" ) var ( @@ -21,7 +22,7 @@ type PeersProvider interface { // NewPeerStore returns an instance of PeerStore. func NewPeerStore(cache *Cache) *PeerStore { return &PeerStore{ - nodes: map[enode.ID]*enode.Node{}, + nodes: map[whispertypes.EnodeID]*enode.Node{}, cache: cache, } } @@ -29,13 +30,13 @@ func NewPeerStore(cache *Cache) *PeerStore { // PeerStore stores list of selected mail servers and keeps N of them connected. type PeerStore struct { mu sync.RWMutex - nodes map[enode.ID]*enode.Node + nodes map[whispertypes.EnodeID]*enode.Node cache *Cache } // Exist confirms that peers was added to a store. -func (ps *PeerStore) Exist(nodeID enode.ID) bool { +func (ps *PeerStore) Exist(nodeID whispertypes.EnodeID) bool { ps.mu.RLock() defer ps.mu.RUnlock() _, exist := ps.nodes[nodeID] @@ -43,7 +44,7 @@ func (ps *PeerStore) Exist(nodeID enode.ID) bool { } // Get returns instance of the node with requested ID or nil if ID is not found. -func (ps *PeerStore) Get(nodeID enode.ID) *enode.Node { +func (ps *PeerStore) Get(nodeID whispertypes.EnodeID) *enode.Node { ps.mu.RLock() defer ps.mu.RUnlock() return ps.nodes[nodeID] @@ -52,9 +53,9 @@ func (ps *PeerStore) Get(nodeID enode.ID) *enode.Node { // Update updates peers locally. func (ps *PeerStore) Update(nodes []*enode.Node) error { ps.mu.Lock() - ps.nodes = map[enode.ID]*enode.Node{} + ps.nodes = map[whispertypes.EnodeID]*enode.Node{} for _, n := range nodes { - ps.nodes[n.ID()] = n + ps.nodes[whispertypes.EnodeID(n.ID())] = n } ps.mu.Unlock() return ps.cache.Replace(nodes) diff --git a/services/shhext/mailservers/peerstore_test.go b/services/shhext/mailservers/peerstore_test.go index 48d7bdbaf..f616c9bef 100644 --- a/services/shhext/mailservers/peerstore_test.go +++ b/services/shhext/mailservers/peerstore_test.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" "github.com/stretchr/testify/require" ) @@ -24,11 +25,11 @@ func TestUpdateResetsInternalStorage(t *testing.T) { r2, err := RandomNode() require.NoError(t, err) require.NoError(t, store.Update([]*enode.Node{r1, r2})) - require.True(t, store.Exist(r1.ID())) - require.True(t, store.Exist(r2.ID())) + require.True(t, store.Exist(whispertypes.EnodeID(r1.ID()))) + require.True(t, store.Exist(whispertypes.EnodeID(r2.ID()))) require.NoError(t, store.Update([]*enode.Node{r2})) - require.False(t, store.Exist(r1.ID())) - require.True(t, store.Exist(r2.ID())) + require.False(t, store.Exist(whispertypes.EnodeID(r1.ID()))) + require.True(t, store.Exist(whispertypes.EnodeID(r2.ID()))) } func TestGetNodeByID(t *testing.T) { @@ -36,8 +37,8 @@ func TestGetNodeByID(t *testing.T) { r1, err := RandomNode() require.NoError(t, err) require.NoError(t, store.Update([]*enode.Node{r1})) - require.Equal(t, r1, store.Get(r1.ID())) - require.Nil(t, store.Get(enode.ID{1})) + require.Equal(t, r1, store.Get(whispertypes.EnodeID(r1.ID()))) + require.Nil(t, store.Get(whispertypes.EnodeID{1})) } type fakePeerProvider struct { diff --git a/services/shhext/mailservers/utils.go b/services/shhext/mailservers/utils.go index c8e3557af..a87571502 100644 --- a/services/shhext/mailservers/utils.go +++ b/services/shhext/mailservers/utils.go @@ -4,6 +4,7 @@ import ( "sort" "github.com/ethereum/go-ethereum/p2p/enode" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" ) // GetFirstConnected returns first connected peer that is also added to a peer store. @@ -11,7 +12,7 @@ import ( func GetFirstConnected(provider PeersProvider, store *PeerStore) (*enode.Node, error) { peers := provider.Peers() for _, p := range peers { - if store.Exist(p.ID()) { + if store.Exist(whispertypes.EnodeID(p.ID())) { return p.Node(), nil } } diff --git a/services/shhext/mailservers/utils_test.go b/services/shhext/mailservers/utils_test.go index 8290af27d..33e9fee19 100644 --- a/services/shhext/mailservers/utils_test.go +++ b/services/shhext/mailservers/utils_test.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" "github.com/stretchr/testify/require" ) @@ -27,7 +28,7 @@ func TestGetFirstConnected(t *testing.T) { require.NoError(t, store.Update(nodes)) node, err := GetFirstConnected(provider, store) require.NoError(t, err) - require.Contains(t, nodesMap, node.ID()) + require.Contains(t, nodesMap, whispertypes.EnodeID(node.ID())) } type trackingNodeNotifee struct { diff --git a/services/shhext/requests.go b/services/shhext/requests.go index 58c541a6e..798cddf92 100644 --- a/services/shhext/requests.go +++ b/services/shhext/requests.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/common" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" ) const ( @@ -17,7 +17,7 @@ const ( type requestMeta struct { timestamp time.Time - lastUID common.Hash + lastUID statusproto.Hash } // NewRequestsRegistry creates instance of the RequestsRegistry and returns pointer to it. @@ -33,13 +33,13 @@ func NewRequestsRegistry(delay time.Duration) *RequestsRegistry { type RequestsRegistry struct { mu sync.Mutex delay time.Duration - uidToTopics map[common.Hash]common.Hash - byTopicsHash map[common.Hash]requestMeta + uidToTopics map[statusproto.Hash]statusproto.Hash + byTopicsHash map[statusproto.Hash]requestMeta } // Register request with given topics. If request with same topics was made in less then configured delay then error // will be returned. -func (r *RequestsRegistry) Register(uid common.Hash, topics []whisper.TopicType) error { +func (r *RequestsRegistry) Register(uid statusproto.Hash, topics []whispertypes.TopicType) error { r.mu.Lock() defer r.mu.Unlock() topicsHash := topicsToHash(topics) @@ -58,7 +58,7 @@ func (r *RequestsRegistry) Register(uid common.Hash, topics []whisper.TopicType) } // Has returns true if given uid is stored in registry. -func (r *RequestsRegistry) Has(uid common.Hash) bool { +func (r *RequestsRegistry) Has(uid statusproto.Hash) bool { r.mu.Lock() defer r.mu.Unlock() _, exist := r.uidToTopics[uid] @@ -66,7 +66,7 @@ func (r *RequestsRegistry) Has(uid common.Hash) bool { } // Unregister removes request with given UID from registry. -func (r *RequestsRegistry) Unregister(uid common.Hash) { +func (r *RequestsRegistry) Unregister(uid statusproto.Hash) { r.mu.Lock() defer r.mu.Unlock() topicsHash, exist := r.uidToTopics[uid] @@ -85,15 +85,15 @@ func (r *RequestsRegistry) Unregister(uid common.Hash) { func (r *RequestsRegistry) Clear() { r.mu.Lock() defer r.mu.Unlock() - r.uidToTopics = map[common.Hash]common.Hash{} - r.byTopicsHash = map[common.Hash]requestMeta{} + r.uidToTopics = map[statusproto.Hash]statusproto.Hash{} + r.byTopicsHash = map[statusproto.Hash]requestMeta{} } // topicsToHash returns non-cryptographic hash of the topics. -func topicsToHash(topics []whisper.TopicType) common.Hash { +func topicsToHash(topics []whispertypes.TopicType) statusproto.Hash { hash := fnv.New32() for i := range topics { _, _ = hash.Write(topics[i][:]) // never returns error per documentation } - return common.BytesToHash(hash.Sum(nil)) + return statusproto.BytesToHash(hash.Sum(nil)) } diff --git a/services/shhext/requests_test.go b/services/shhext/requests_test.go index 574d0a1b9..9e73264e6 100644 --- a/services/shhext/requests_test.go +++ b/services/shhext/requests_test.go @@ -4,39 +4,39 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/stretchr/testify/require" ) func TestRegisterSameRequests(t *testing.T) { registry := NewRequestsRegistry(10 * time.Second) - topics := []whisper.TopicType{{1}} - require.NoError(t, registry.Register(common.Hash{1}, topics)) - require.Error(t, registry.Register(common.Hash{2}, topics)) + topics := []whispertypes.TopicType{{1}} + require.NoError(t, registry.Register(statusproto.Hash{1}, topics)) + require.Error(t, registry.Register(statusproto.Hash{2}, topics)) } func TestRegisterSameRequestsWithoutDelay(t *testing.T) { registry := NewRequestsRegistry(0) - topics := []whisper.TopicType{{1}} - require.NoError(t, registry.Register(common.Hash{1}, topics)) - require.NoError(t, registry.Register(common.Hash{2}, topics)) + topics := []whispertypes.TopicType{{1}} + require.NoError(t, registry.Register(statusproto.Hash{1}, topics)) + require.NoError(t, registry.Register(statusproto.Hash{2}, topics)) } func TestRegisterDifferentRequests(t *testing.T) { registry := NewRequestsRegistry(10 * time.Second) - require.NoError(t, registry.Register(common.Hash{1}, []whisper.TopicType{{1}})) - require.NoError(t, registry.Register(common.Hash{2}, []whisper.TopicType{{2}})) + require.NoError(t, registry.Register(statusproto.Hash{1}, []whispertypes.TopicType{{1}})) + require.NoError(t, registry.Register(statusproto.Hash{2}, []whispertypes.TopicType{{2}})) } func TestUnregisterReplacedRequest(t *testing.T) { registry := NewRequestsRegistry(0) - unreg := common.Hash{1} - topics := []whisper.TopicType{{1}} + unreg := statusproto.Hash{1} + topics := []whispertypes.TopicType{{1}} require.NoError(t, registry.Register(unreg, topics)) - replacement := common.Hash{2} + replacement := statusproto.Hash{2} require.NoError(t, registry.Register(replacement, topics)) - // record should be replaced with common.Hash{2}, so when we will remove unreg it will not affect topics map + // record should be replaced with statusproto.Hash{2}, so when we will remove unreg it will not affect topics map registry.Unregister(unreg) record, exist := registry.uidToTopics[replacement] require.True(t, exist, "replaced record should exist") diff --git a/services/shhext/service.go b/services/shhext/service.go index 05cc342c9..a7d06db3c 100644 --- a/services/shhext/service.go +++ b/services/shhext/service.go @@ -6,12 +6,12 @@ import ( "database/sql" "encoding/hex" "fmt" - "github.com/status-im/status-go/logutils" "os" "path/filepath" "time" - "github.com/ethereum/go-ethereum/common" + "github.com/status-im/status-go/logutils" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" @@ -27,7 +27,8 @@ import ( protocol "github.com/status-im/status-protocol-go" protocolwhisper "github.com/status-im/status-protocol-go/transport/whisper" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "github.com/syndtr/goleveldb/leveldb" "go.uber.org/zap" ) @@ -43,8 +44,8 @@ const ( type EnvelopeEventsHandler interface { EnvelopeSent([][]byte) EnvelopeExpired([][]byte, error) - MailServerRequestCompleted(common.Hash, common.Hash, []byte, error) - MailServerRequestExpired(common.Hash) + MailServerRequestCompleted(statusproto.Hash, statusproto.Hash, []byte, error) + MailServerRequestExpired(statusproto.Hash) } // Service is a service that provides some additional Whisper API. @@ -53,7 +54,7 @@ type Service struct { cancelMessenger chan struct{} storage db.TransactionalStorage - w *whisper.Whisper + w whispertypes.Whisper config params.ShhextConfig mailMonitor *MailRequestMonitor requestsRegistry *RequestsRegistry @@ -71,7 +72,7 @@ type Service struct { var _ node.Service = (*Service)(nil) // New returns a new Service. -func New(w *whisper.Whisper, handler EnvelopeEventsHandler, ldb *leveldb.DB, config params.ShhextConfig) *Service { +func New(w whispertypes.Whisper, handler EnvelopeEventsHandler, ldb *leveldb.DB, config params.ShhextConfig) *Service { cache := mailservers.NewCache(ldb) ps := mailservers.NewPeerStore(cache) delay := defaultRequestsDelay @@ -83,7 +84,7 @@ func New(w *whisper.Whisper, handler EnvelopeEventsHandler, ldb *leveldb.DB, con mailMonitor := &MailRequestMonitor{ w: w, handler: handler, - cache: map[common.Hash]EnvelopeState{}, + cache: map[statusproto.Hash]EnvelopeState{}, requestsRegistry: requestsRegistry, } return &Service{ @@ -119,7 +120,7 @@ func (s *Service) InitProtocol(db *sql.DB) error { // nolint: gocyclo envelopesMonitorConfig := &protocolwhisper.EnvelopesMonitorConfig{ MaxAttempts: s.config.MaxMessageDeliveryAttempts, MailserverConfirmationsEnabled: s.config.MailServerConfirmations, - IsMailserver: func(peer enode.ID) bool { + IsMailserver: func(peer whispertypes.EnodeID) bool { return s.peerStore.Exist(peer) }, EnvelopeEventsHandler: EnvelopeSignalHandler{}, @@ -343,7 +344,7 @@ func (s *Service) Stop() error { return nil } -func (s *Service) syncMessages(ctx context.Context, mailServerID []byte, r whisper.SyncMailRequest) (resp whisper.SyncEventResponse, err error) { +func (s *Service) syncMessages(ctx context.Context, mailServerID []byte, r whispertypes.SyncMailRequest) (resp whispertypes.SyncEventResponse, err error) { err = s.w.SyncMessages(mailServerID, r) if err != nil { return @@ -351,7 +352,7 @@ func (s *Service) syncMessages(ctx context.Context, mailServerID []byte, r whisp // Wait for the response which is received asynchronously as a p2p packet. // This packet handler will send an event which contains the response payload. - events := make(chan whisper.EnvelopeEvent, 1024) + events := make(chan whispertypes.EnvelopeEvent, 1024) sub := s.w.SubscribeEnvelopeEvents(events) defer sub.Unsubscribe() @@ -365,7 +366,7 @@ func (s *Service) syncMessages(ctx context.Context, mailServerID []byte, r whisp for { select { case event := <-events: - if event.Event != whisper.EventMailServerSyncFinished { + if event.Event != whispertypes.EventMailServerSyncFinished { continue } @@ -373,7 +374,7 @@ func (s *Service) syncMessages(ctx context.Context, mailServerID []byte, r whisp var ok bool - resp, ok = event.Data.(whisper.SyncEventResponse) + resp, ok = event.Data.(whispertypes.SyncEventResponse) if !ok { err = fmt.Errorf("did not understand the response event data") return diff --git a/services/shhext/service_test.go b/services/shhext/service_test.go index 8f66e9b86..fd4028c2b 100644 --- a/services/shhext/service_test.go +++ b/services/shhext/service_test.go @@ -23,6 +23,9 @@ import ( "github.com/status-im/status-go/sqlite" "github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/t/utils" + "github.com/status-im/status-protocol-go/transport/whisper/gethbridge" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" whisper "github.com/status-im/whisper/whisperv6" "github.com/stretchr/testify/suite" "github.com/syndtr/goleveldb/leveldb" @@ -44,18 +47,18 @@ func newHandlerMock(buf int) handlerMock { return handlerMock{ confirmations: make(chan [][]byte, buf), expirations: make(chan failureMessage, buf), - requestsCompleted: make(chan common.Hash, buf), - requestsExpired: make(chan common.Hash, buf), - requestsFailed: make(chan common.Hash, buf), + requestsCompleted: make(chan statusproto.Hash, buf), + requestsExpired: make(chan statusproto.Hash, buf), + requestsFailed: make(chan statusproto.Hash, buf), } } type handlerMock struct { confirmations chan [][]byte expirations chan failureMessage - requestsCompleted chan common.Hash - requestsExpired chan common.Hash - requestsFailed chan common.Hash + requestsCompleted chan statusproto.Hash + requestsExpired chan statusproto.Hash + requestsFailed chan statusproto.Hash } func (t handlerMock) EnvelopeSent(ids [][]byte) { @@ -66,7 +69,7 @@ func (t handlerMock) EnvelopeExpired(ids [][]byte, err error) { t.expirations <- failureMessage{IDs: ids, Error: err} } -func (t handlerMock) MailServerRequestCompleted(requestID common.Hash, lastEnvelopeHash common.Hash, cursor []byte, err error) { +func (t handlerMock) MailServerRequestCompleted(requestID statusproto.Hash, lastEnvelopeHash statusproto.Hash, cursor []byte, err error) { if err == nil { t.requestsCompleted <- requestID } else { @@ -74,7 +77,7 @@ func (t handlerMock) MailServerRequestCompleted(requestID common.Hash, lastEnvel } } -func (t handlerMock) MailServerRequestExpired(hash common.Hash) { +func (t handlerMock) MailServerRequestExpired(hash statusproto.Hash) { t.requestsExpired <- hash } @@ -87,13 +90,13 @@ type ShhExtSuite struct { nodes []*node.Node services []*Service - whisper []*whisper.Whisper + whisper []whispertypes.Whisper } func (s *ShhExtSuite) SetupTest() { s.nodes = make([]*node.Node, 2) s.services = make([]*Service, 2) - s.whisper = make([]*whisper.Whisper, 2) + s.whisper = make([]whispertypes.Whisper, 2) directory, err := ioutil.TempDir("", "status-go-testing") s.Require().NoError(err) @@ -111,7 +114,7 @@ func (s *ShhExtSuite) SetupTest() { } stack, err := node.New(cfg) s.NoError(err) - s.whisper[i] = whisper.New(nil) + s.whisper[i] = gethbridge.NewGethWhisperWrapper(whisper.New(nil)) privateKey, err := crypto.GenerateKey() s.NoError(err) @@ -119,7 +122,7 @@ func (s *ShhExtSuite) SetupTest() { s.NoError(err) s.NoError(stack.Register(func(n *node.ServiceContext) (node.Service, error) { - return s.whisper[i], nil + return gethbridge.GetGethWhisperFrom(s.whisper[i]), nil })) config := params.ShhextConfig{ @@ -162,7 +165,7 @@ func (s *ShhExtSuite) TestInitProtocol() { db, err := leveldb.Open(storage.NewMemStorage(), nil) s.Require().NoError(err) - shh := whisper.New(nil) + shh := gethbridge.NewGethWhisperWrapper(whisper.New(nil)) privateKey, err := crypto.GenerateKey() s.Require().NoError(err) err = shh.SelectKeyPair(privateKey) @@ -183,7 +186,7 @@ func (s *ShhExtSuite) TestInitProtocol() { func (s *ShhExtSuite) TestRequestMessagesErrors() { var err error - shh := whisper.New(nil) + shh := gethbridge.NewGethWhisperWrapper(whisper.New(nil)) aNode, err := node.New(&node.Config{ P2P: p2p.Config{ MaxPeers: math.MaxInt32, @@ -193,7 +196,7 @@ func (s *ShhExtSuite) TestRequestMessagesErrors() { }) // in-memory node as no data dir s.NoError(err) err = aNode.Register(func(*node.ServiceContext) (node.Service, error) { - return shh, nil + return gethbridge.GetGethWhisperFrom(shh), nil }) s.NoError(err) @@ -256,15 +259,15 @@ func (s *ShhExtSuite) TestMultipleRequestMessagesWithoutForce() { s.NoError(err) s.NoError(client.Call(nil, "shhext_requestMessages", MessagesRequest{ MailServerPeer: s.nodes[1].Server().Self().URLv4(), - Topics: []whisper.TopicType{{1}}, + Topics: []whispertypes.TopicType{{1}}, })) s.EqualError(client.Call(nil, "shhext_requestMessages", MessagesRequest{ MailServerPeer: s.nodes[1].Server().Self().URLv4(), - Topics: []whisper.TopicType{{1}}, + Topics: []whispertypes.TopicType{{1}}, }), "another request with the same topics was sent less than 3s ago. Please wait for a bit longer, or set `force` to true in request parameters") s.NoError(client.Call(nil, "shhext_requestMessages", MessagesRequest{ MailServerPeer: s.nodes[1].Server().Self().URLv4(), - Topics: []whisper.TopicType{{2}}, + Topics: []whispertypes.TopicType{{2}}, })) } @@ -273,7 +276,7 @@ func (s *ShhExtSuite) TestFailedRequestUnregistered() { s.nodes[0].Server().AddPeer(s.nodes[1].Server().Self()) s.Require().NoError(<-waitErr) client, err := s.nodes[0].Attach() - topics := []whisper.TopicType{{1}} + topics := []whispertypes.TopicType{{1}} s.NoError(err) s.EqualError(client.Call(nil, "shhext_requestMessages", MessagesRequest{ MailServerPeer: "enode://19872f94b1e776da3a13e25afa71b47dfa99e658afd6427ea8d6e03c22a99f13590205a8826443e95a37eee1d815fc433af7a8ca9a8d0df7943d1f55684045b7@0.0.0.0:30305", @@ -288,7 +291,7 @@ func (s *ShhExtSuite) TestFailedRequestUnregistered() { func (s *ShhExtSuite) TestRequestMessagesSuccess() { var err error - shh := whisper.New(nil) + shh := gethbridge.NewGethWhisperWrapper(whisper.New(nil)) privateKey, err := crypto.GenerateKey() s.Require().NoError(err) err = shh.SelectKeyPair(privateKey) @@ -301,7 +304,7 @@ func (s *ShhExtSuite) TestRequestMessagesSuccess() { NoUSB: true, }) // in-memory node as no data dir s.Require().NoError(err) - err = aNode.Register(func(*node.ServiceContext) (node.Service, error) { return shh, nil }) + err = aNode.Register(func(*node.ServiceContext) (node.Service, error) { return gethbridge.GetGethWhisperFrom(shh), nil }) s.Require().NoError(err) err = aNode.Start() @@ -408,10 +411,11 @@ func (s *WhisperNodeMockSuite) SetupTest() { err := w.HandlePeer(peer, rw2) errorc <- err }() - s.Require().NoError(p2p.ExpectMsg(rw1, statusCode, []interface{}{whisper.ProtocolVersion, math.Float64bits(w.MinPow()), w.BloomFilter(), false, true})) - s.Require().NoError(p2p.SendItems(rw1, statusCode, whisper.ProtocolVersion, whisper.ProtocolVersion, math.Float64bits(w.MinPow()), w.BloomFilter(), true, true)) + whisperWrapper := gethbridge.NewGethWhisperWrapper(w) + s.Require().NoError(p2p.ExpectMsg(rw1, statusCode, []interface{}{whisper.ProtocolVersion, math.Float64bits(whisperWrapper.MinPow()), whisperWrapper.BloomFilter(), false, true})) + s.Require().NoError(p2p.SendItems(rw1, statusCode, whisper.ProtocolVersion, whisper.ProtocolVersion, math.Float64bits(whisperWrapper.MinPow()), whisperWrapper.BloomFilter(), true, true)) - s.localService = New(w, nil, db, params.ShhextConfig{MailServerConfirmations: true, MaxMessageDeliveryAttempts: 3}) + s.localService = New(whisperWrapper, nil, db, params.ShhextConfig{MailServerConfirmations: true, MaxMessageDeliveryAttempts: 3}) s.Require().NoError(s.localService.UpdateMailservers([]*enode.Node{node})) s.localWhisperAPI = whisper.NewPublicWhisperAPI(w) @@ -514,7 +518,7 @@ type RequestWithTrackingHistorySuite struct { envelopeSymkey string envelopeSymkeyID string - localWhisperAPI *whisper.PublicWhisperAPI + localWhisperAPI whispertypes.PublicWhisperAPI localAPI *PublicAPI localService *Service localContext Context @@ -532,10 +536,11 @@ func (s *RequestWithTrackingHistorySuite) SetupTest() { MinimumAcceptedPOW: 0, MaxMessageSize: 100 << 10, } - local := whisper.New(conf) - s.Require().NoError(local.Start(nil)) + localSHH := whisper.New(conf) + local := gethbridge.NewGethWhisperWrapper(localSHH) + s.Require().NoError(localSHH.Start(nil)) - s.localWhisperAPI = whisper.NewPublicWhisperAPI(local) + s.localWhisperAPI = local.PublicWhisperAPI() s.localService = New(local, nil, db, params.ShhextConfig{}) s.localContext = NewContextFromService(context.Background(), s.localService, s.localService.storage) localPkey, err := crypto.GenerateKey() @@ -551,15 +556,15 @@ func (s *RequestWithTrackingHistorySuite) SetupTest() { s.Require().NoError(s.localService.Start(&p2p.Server{Config: p2p.Config{PrivateKey: localPkey}})) s.localAPI = NewPublicAPI(s.localService) - remote := whisper.New(conf) - s.remoteWhisper = remote - s.Require().NoError(remote.Start(nil)) + remoteSHH := whisper.New(conf) + s.remoteWhisper = remoteSHH + s.Require().NoError(remoteSHH.Start(nil)) s.remoteMailserver = &mailserver.WMailServer{} - remote.RegisterServer(s.remoteMailserver) + remoteSHH.RegisterServer(s.remoteMailserver) password := "test" tmpdir, err = ioutil.TempDir("", "tracking-history-tests-") s.Require().NoError(err) - s.Require().NoError(s.remoteMailserver.Init(remote, ¶ms.WhisperConfig{ + s.Require().NoError(s.remoteMailserver.Init(remoteSHH, ¶ms.WhisperConfig{ DataDir: tmpdir, MailServerPassword: password, })) @@ -573,11 +578,11 @@ func (s *RequestWithTrackingHistorySuite) SetupTest() { // FIXME close this in tear down rw1, rw2 := p2p.MsgPipe() go func() { - err := local.HandlePeer(remotePeer, rw1) + err := localSHH.HandlePeer(remotePeer, rw1) s.Require().NoError(err) }() go func() { - err := remote.HandlePeer(localPeer, rw2) + err := remoteSHH.HandlePeer(localPeer, rw2) s.Require().NoError(err) }() s.mailSymKey, err = s.localWhisperAPI.GenerateSymKeyFromPassword(context.Background(), password) @@ -588,13 +593,13 @@ func (s *RequestWithTrackingHistorySuite) SetupTest() { s.Require().NoError(err) } -func (s *RequestWithTrackingHistorySuite) postEnvelopes(topics ...whisper.TopicType) []hexutil.Bytes { +func (s *RequestWithTrackingHistorySuite) postEnvelopes(topics ...whispertypes.TopicType) []hexutil.Bytes { var ( rst = make([]hexutil.Bytes, len(topics)) err error ) for i, t := range topics { - rst[i], err = s.localWhisperAPI.Post(context.Background(), whisper.NewMessage{ + rst[i], err = s.localWhisperAPI.Post(context.Background(), whispertypes.NewMessage{ SymKeyID: s.envelopeSymkeyID, TTL: 10, Topic: t, @@ -612,8 +617,8 @@ func (s *RequestWithTrackingHistorySuite) waitForArchival(hexes []hexutil.Bytes) s.Require().NoError(waitForArchival(events, 2*time.Second, hexes...)) } -func (s *RequestWithTrackingHistorySuite) createEmptyFilter(topics ...whisper.TopicType) string { - filterid, err := s.localWhisperAPI.NewMessageFilter(whisper.Criteria{ +func (s *RequestWithTrackingHistorySuite) createEmptyFilter(topics ...whispertypes.TopicType) string { + filterid, err := s.localWhisperAPI.NewMessageFilter(whispertypes.Criteria{ SymKeyID: s.envelopeSymkeyID, Topics: topics, AllowP2P: true, @@ -627,7 +632,7 @@ func (s *RequestWithTrackingHistorySuite) createEmptyFilter(topics ...whisper.To return filterid } -func (s *RequestWithTrackingHistorySuite) initiateHistoryRequest(topics ...TopicRequest) []hexutil.Bytes { +func (s *RequestWithTrackingHistorySuite) initiateHistoryRequest(topics ...TopicRequest) []statusproto.HexBytes { requests, err := s.localAPI.InitiateHistoryRequests(context.Background(), InitiateHistoryRequestParams{ Peer: s.remoteNode.String(), SymKeyID: s.mailSymKey, @@ -651,7 +656,6 @@ func (s *RequestWithTrackingHistorySuite) waitMessagesDelivered(filterid string, } return nil }, 2*time.Second, 200*time.Millisecond)) - } func (s *RequestWithTrackingHistorySuite) waitNoRequests() { @@ -669,9 +673,9 @@ func (s *RequestWithTrackingHistorySuite) waitNoRequests() { } func (s *RequestWithTrackingHistorySuite) TestMultipleMergeIntoOne() { - topic1 := whisper.TopicType{1, 1, 1, 1} - topic2 := whisper.TopicType{2, 2, 2, 2} - topic3 := whisper.TopicType{3, 3, 3, 3} + topic1 := whispertypes.TopicType{1, 1, 1, 1} + topic2 := whispertypes.TopicType{2, 2, 2, 2} + topic3 := whispertypes.TopicType{3, 3, 3, 3} hexes := s.postEnvelopes(topic1, topic2, topic3) s.waitForArchival(hexes) @@ -683,6 +687,7 @@ func (s *RequestWithTrackingHistorySuite) TestMultipleMergeIntoOne() { ) // since we are using different duration for 3rd topic there will be 2 requests s.Require().Len(requests, 2) + s.Require().NotEqual(requests[0], requests[1]) s.waitMessagesDelivered(filterid, hexes...) s.Require().NoError(s.localService.historyUpdates.UpdateTopicHistory(s.localContext, topic1, time.Now())) @@ -702,8 +707,8 @@ func (s *RequestWithTrackingHistorySuite) TestMultipleMergeIntoOne() { } func (s *RequestWithTrackingHistorySuite) TestSingleRequest() { - topic1 := whisper.TopicType{1, 1, 1, 1} - topic2 := whisper.TopicType{255, 255, 255, 255} + topic1 := whispertypes.TopicType{1, 1, 1, 1} + topic2 := whispertypes.TopicType{255, 255, 255, 255} hexes := s.postEnvelopes(topic1, topic2) s.waitForArchival(hexes) @@ -717,8 +722,8 @@ func (s *RequestWithTrackingHistorySuite) TestSingleRequest() { } func (s *RequestWithTrackingHistorySuite) TestPreviousRequestReplaced() { - topic1 := whisper.TopicType{1, 1, 1, 1} - topic2 := whisper.TopicType{255, 255, 255, 255} + topic1 := whispertypes.TopicType{1, 1, 1, 1} + topic2 := whispertypes.TopicType{255, 255, 255, 255} requests := s.initiateHistoryRequest( TopicRequest{Topic: topic1, Duration: time.Hour}, diff --git a/services/shhext/signal.go b/services/shhext/signal.go index 4fca376f7..f17e2ee60 100644 --- a/services/shhext/signal.go +++ b/services/shhext/signal.go @@ -1,8 +1,8 @@ package shhext import ( - "github.com/ethereum/go-ethereum/common" "github.com/status-im/status-go/signal" + statusproto "github.com/status-im/status-protocol-go/types" ) // EnvelopeSignalHandler sends signals when envelope is sent or expired. @@ -19,12 +19,12 @@ func (h EnvelopeSignalHandler) EnvelopeExpired(identifiers [][]byte, err error) } // MailServerRequestCompleted triggered when the mailserver sends a message to notify that the request has been completed -func (h EnvelopeSignalHandler) MailServerRequestCompleted(requestID common.Hash, lastEnvelopeHash common.Hash, cursor []byte, err error) { +func (h EnvelopeSignalHandler) MailServerRequestCompleted(requestID statusproto.Hash, lastEnvelopeHash statusproto.Hash, cursor []byte, err error) { signal.SendMailServerRequestCompleted(requestID, lastEnvelopeHash, cursor, err) } // MailServerRequestExpired triggered when the mailserver request expires -func (h EnvelopeSignalHandler) MailServerRequestExpired(hash common.Hash) { +func (h EnvelopeSignalHandler) MailServerRequestExpired(hash statusproto.Hash) { signal.SendMailServerRequestExpired(hash) } diff --git a/services/shhext/whisperutils/whisper.go b/services/shhext/whisperutils/whisper.go index d920b81dc..89be86bca 100644 --- a/services/shhext/whisperutils/whisper.go +++ b/services/shhext/whisperutils/whisper.go @@ -11,13 +11,3 @@ var DiscoveryTopicBytes = ToTopic(discoveryTopic) func ToTopic(s string) whisper.TopicType { return whisper.BytesToTopic(crypto.Keccak256([]byte(s))) } - -func DefaultWhisperMessage() whisper.NewMessage { - msg := whisper.NewMessage{} - - msg.TTL = 10 - msg.PowTarget = 0.002 - msg.PowTime = 1 - - return msg -} diff --git a/signal/events_shhext.go b/signal/events_shhext.go index 82fec2560..a8b20440d 100644 --- a/signal/events_shhext.go +++ b/signal/events_shhext.go @@ -3,12 +3,12 @@ package signal import ( "encoding/hex" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/status-im/status-go/services/shhext/dedup" - whisper "github.com/status-im/whisper/whisperv6" statustransp "github.com/status-im/status-protocol-go/transport/whisper" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" ) const ( @@ -46,17 +46,17 @@ const ( // EnvelopeSignal includes hash of the envelope. type EnvelopeSignal struct { - IDs []hexutil.Bytes `json:"ids"` - Hash common.Hash `json:"hash"` - Message string `json:"message"` + IDs []hexutil.Bytes `json:"ids"` + Hash statusproto.Hash `json:"hash"` + Message string `json:"message"` } // MailServerResponseSignal holds the data received in the response from the mailserver. type MailServerResponseSignal struct { - RequestID common.Hash `json:"requestID"` - LastEnvelopeHash common.Hash `json:"lastEnvelopeHash"` - Cursor string `json:"cursor"` - ErrorMsg string `json:"errorMessage"` + RequestID statusproto.Hash `json:"requestID"` + LastEnvelopeHash statusproto.Hash `json:"lastEnvelopeHash"` + Cursor string `json:"cursor"` + ErrorMsg string `json:"errorMessage"` } // DecryptMessageFailedSignal holds the sender of the message that could not be decrypted @@ -82,7 +82,7 @@ type Filter struct { // Identity is the public key of the other recipient for non-public chats Identity string `json:"identity"` // Topic is the whisper topic - Topic whisper.TopicType `json:"topic"` + Topic whispertypes.TopicType `json:"topic"` } type WhisperFilterAddedSignal struct { @@ -121,7 +121,7 @@ func SendEnvelopeExpired(identifiers [][]byte, err error) { } // SendMailServerRequestCompleted triggered when mail server response has been received -func SendMailServerRequestCompleted(requestID common.Hash, lastEnvelopeHash common.Hash, cursor []byte, err error) { +func SendMailServerRequestCompleted(requestID statusproto.Hash, lastEnvelopeHash statusproto.Hash, cursor []byte, err error) { errorMsg := "" if err != nil { errorMsg = err.Error() @@ -136,7 +136,7 @@ func SendMailServerRequestCompleted(requestID common.Hash, lastEnvelopeHash comm } // SendMailServerRequestExpired triggered when mail server request expires -func SendMailServerRequestExpired(hash common.Hash) { +func SendMailServerRequestExpired(hash statusproto.Hash) { send(EventMailServerRequestExpired, EnvelopeSignal{Hash: hash}) } diff --git a/t/benchmarks/mailserver_test.go b/t/benchmarks/mailserver_test.go index 5f594c5f4..660fd0859 100644 --- a/t/benchmarks/mailserver_test.go +++ b/t/benchmarks/mailserver_test.go @@ -10,6 +10,8 @@ import ( "github.com/ethereum/go-ethereum/node" "github.com/status-im/status-go/params" "github.com/status-im/status-go/services/shhext" + "github.com/status-im/status-protocol-go/transport/whisper/gethbridge" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" whisper "github.com/status-im/whisper/whisperv6" "github.com/stretchr/testify/require" ) @@ -41,7 +43,7 @@ func testMailserverPeer(t *testing.T) { BackupDisabledDataDir: os.TempDir(), InstallationID: "1", } - mailService := shhext.New(shhService, nil, nil, config) + mailService := shhext.New(gethbridge.NewGethWhisperWrapper(shhService), nil, nil, config) shhextAPI := shhext.NewPublicAPI(mailService) // create node with services @@ -88,7 +90,7 @@ func testMailserverPeer(t *testing.T) { requestID, err := shhextAPI.RequestMessages(context.TODO(), shhext.MessagesRequest{ MailServerPeer: *peerURL, SymKeyID: symKeyID, - Topic: topic, + Topic: whispertypes.TopicType(topic), }) require.NoError(t, err) require.NotNil(t, requestID) diff --git a/vendor/github.com/allegro/bigcache/.gitignore b/vendor/github.com/allegro/bigcache/.gitignore index 256d66590..372c42cb5 100644 --- a/vendor/github.com/allegro/bigcache/.gitignore +++ b/vendor/github.com/allegro/bigcache/.gitignore @@ -2,9 +2,4 @@ .DS_Store /server/server.exe /server/server -/server/server_dar* -/server/server_fre* -/server/server_win* -/server/server_net* -/server/server_ope* CHANGELOG.md diff --git a/vendor/github.com/allegro/bigcache/.travis.yml b/vendor/github.com/allegro/bigcache/.travis.yml index cc28df6a9..a9d987ef9 100644 --- a/vendor/github.com/allegro/bigcache/.travis.yml +++ b/vendor/github.com/allegro/bigcache/.travis.yml @@ -14,7 +14,7 @@ before_install: - go get github.com/mattn/goveralls - go get golang.org/x/tools/cmd/cover - go get golang.org/x/tools/cmd/goimports - - go get golang.org/x/lint/golint + - go get github.com/golang/lint/golint - go get github.com/stretchr/testify/assert - go get github.com/gordonklaus/ineffassign diff --git a/vendor/github.com/allegro/bigcache/README.md b/vendor/github.com/allegro/bigcache/README.md index c23f7f36c..cd462d362 100644 --- a/vendor/github.com/allegro/bigcache/README.md +++ b/vendor/github.com/allegro/bigcache/README.md @@ -46,15 +46,10 @@ config := bigcache.Config { // if value is reached then the oldest entries can be overridden for the new ones // 0 value means no size limit HardMaxCacheSize: 8192, - // callback fired when the oldest entry is removed because of its expiration time or no space left - // for the new entry, or because delete was called. A bitmask representing the reason will be returned. - // Default value is nil which means no callback and it prevents from unwrapping the oldest entry. + // callback fired when the oldest entry is removed because of its + // expiration time or no space left for the new entry. Default value is nil which + // means no callback and it prevents from unwrapping the oldest entry. OnRemove: nil, - // OnRemoveWithReason is a callback fired when the oldest entry is removed because of its expiration time or no space left - // for the new entry, or because delete was called. A constant representing the reason will be passed through. - // Default value is nil which means no callback and it prevents from unwrapping the oldest entry. - // Ignored if OnRemove is specified. - OnRemoveWithReason: nil, } cache, initErr := bigcache.NewBigCache(config) @@ -79,20 +74,20 @@ Benchmark tests were made using an i7-6700K with 32GB of RAM on Windows 10. ```bash cd caches_bench; go test -bench=. -benchtime=10s ./... -timeout 30m -BenchmarkMapSet-8 3000000 569 ns/op 202 B/op 3 allocs/op -BenchmarkConcurrentMapSet-8 1000000 1592 ns/op 347 B/op 8 allocs/op -BenchmarkFreeCacheSet-8 3000000 775 ns/op 355 B/op 2 allocs/op -BenchmarkBigCacheSet-8 3000000 640 ns/op 303 B/op 2 allocs/op -BenchmarkMapGet-8 5000000 407 ns/op 24 B/op 1 allocs/op -BenchmarkConcurrentMapGet-8 3000000 558 ns/op 24 B/op 2 allocs/op -BenchmarkFreeCacheGet-8 2000000 682 ns/op 136 B/op 2 allocs/op -BenchmarkBigCacheGet-8 3000000 512 ns/op 152 B/op 4 allocs/op -BenchmarkBigCacheSetParallel-8 10000000 225 ns/op 313 B/op 3 allocs/op -BenchmarkFreeCacheSetParallel-8 10000000 218 ns/op 341 B/op 3 allocs/op -BenchmarkConcurrentMapSetParallel-8 5000000 318 ns/op 200 B/op 6 allocs/op -BenchmarkBigCacheGetParallel-8 20000000 178 ns/op 152 B/op 4 allocs/op -BenchmarkFreeCacheGetParallel-8 20000000 295 ns/op 136 B/op 3 allocs/op -BenchmarkConcurrentMapGetParallel-8 10000000 237 ns/op 24 B/op 2 allocs/op +BenchmarkMapSet-8 2000000 716 ns/op 336 B/op 3 allocs/op +BenchmarkConcurrentMapSet-8 1000000 1292 ns/op 347 B/op 8 allocs/op +BenchmarkFreeCacheSet-8 3000000 501 ns/op 371 B/op 3 allocs/op +BenchmarkBigCacheSet-8 3000000 482 ns/op 303 B/op 2 allocs/op +BenchmarkMapGet-8 5000000 309 ns/op 24 B/op 1 allocs/op +BenchmarkConcurrentMapGet-8 2000000 659 ns/op 24 B/op 2 allocs/op +BenchmarkFreeCacheGet-8 3000000 541 ns/op 152 B/op 3 allocs/op +BenchmarkBigCacheGet-8 3000000 420 ns/op 152 B/op 3 allocs/op +BenchmarkBigCacheSetParallel-8 10000000 184 ns/op 313 B/op 3 allocs/op +BenchmarkFreeCacheSetParallel-8 10000000 195 ns/op 357 B/op 4 allocs/op +BenchmarkConcurrentMapSetParallel-8 5000000 242 ns/op 200 B/op 6 allocs/op +BenchmarkBigCacheGetParallel-8 20000000 100 ns/op 152 B/op 4 allocs/op +BenchmarkFreeCacheGetParallel-8 10000000 133 ns/op 152 B/op 4 allocs/op +BenchmarkConcurrentMapGetParallel-8 10000000 202 ns/op 24 B/op 2 allocs/op ``` Writes and reads in bigcache are faster than in freecache. diff --git a/vendor/github.com/allegro/bigcache/bigcache.go b/vendor/github.com/allegro/bigcache/bigcache.go index b3879264a..3a6f6bd66 100644 --- a/vendor/github.com/allegro/bigcache/bigcache.go +++ b/vendor/github.com/allegro/bigcache/bigcache.go @@ -10,7 +10,7 @@ const ( ) // BigCache is fast, concurrent, evicting cache created to keep big number of entries without impact on performance. -// It keeps entries on heap but omits GC for them. To achieve that, operations take place on byte arrays, +// It keeps entries on heap but omits GC for them. To achieve that operations on bytes arrays take place, // therefore entries (de)serialization in front of the cache will be needed in most use cases. type BigCache struct { shards []*cacheShard @@ -20,22 +20,8 @@ type BigCache struct { config Config shardMask uint64 maxShardSize uint32 - close chan struct{} } -// RemoveReason is a value used to signal to the user why a particular key was removed in the OnRemove callback. -type RemoveReason uint32 - -const ( - // Expired means the key is past its LifeWindow. - Expired RemoveReason = iota - // NoSpace means the key is the oldest and the cache size was at its maximum when Set was called, or the - // entry exceeded the maximum shard size. - NoSpace - // Deleted means Delete was called and this key was removed as a result. - Deleted -) - // NewBigCache initialize new instance of BigCache func NewBigCache(config Config) (*BigCache, error) { return newBigCache(config, &systemClock{}) @@ -59,16 +45,13 @@ func newBigCache(config Config, clock clock) (*BigCache, error) { config: config, shardMask: uint64(config.Shards - 1), maxShardSize: uint32(config.maximumShardSize()), - close: make(chan struct{}), } - var onRemove func(wrappedEntry []byte, reason RemoveReason) - if config.OnRemove != nil { - onRemove = cache.providedOnRemove - } else if config.OnRemoveWithReason != nil { - onRemove = cache.providedOnRemoveWithReason - } else { + var onRemove func(wrappedEntry []byte) + if config.OnRemove == nil { onRemove = cache.notProvidedOnRemove + } else { + onRemove = cache.providedOnRemove } for i := 0; i < config.Shards; i++ { @@ -77,15 +60,8 @@ func newBigCache(config Config, clock clock) (*BigCache, error) { if config.CleanWindow > 0 { go func() { - ticker := time.NewTicker(config.CleanWindow) - defer ticker.Stop() - for { - select { - case t := <-ticker.C: - cache.cleanUp(uint64(t.Unix())) - case <-cache.close: - return - } + for t := range time.Tick(config.CleanWindow) { + cache.cleanUp(uint64(t.Unix())) } }() } @@ -93,16 +69,8 @@ func newBigCache(config Config, clock clock) (*BigCache, error) { return cache, nil } -// Close is used to signal a shutdown of the cache when you are done with it. -// This allows the cleaning goroutines to exit and ensures references are not -// kept to the cache preventing GC of the entire cache. -func (c *BigCache) Close() error { - close(c.close) - return nil -} - // Get reads entry for the key. -// It returns an ErrEntryNotFound when +// It returns an EntryNotFoundError when // no entry exists for the given key. func (c *BigCache) Get(key string) ([]byte, error) { hashedKey := c.hash.Sum64(key) @@ -141,15 +109,6 @@ func (c *BigCache) Len() int { return len } -// Capacity returns amount of bytes store in the cache. -func (c *BigCache) Capacity() int { - var len int - for _, shard := range c.shards { - len += shard.capacity() - } - return len -} - // Stats returns cache's statistics func (c *BigCache) Stats() Stats { var s Stats @@ -169,10 +128,10 @@ func (c *BigCache) Iterator() *EntryInfoIterator { return newIterator(c) } -func (c *BigCache) onEvict(oldestEntry []byte, currentTimestamp uint64, evict func(reason RemoveReason) error) bool { +func (c *BigCache) onEvict(oldestEntry []byte, currentTimestamp uint64, evict func() error) bool { oldestTimestamp := readTimestampFromEntry(oldestEntry) if currentTimestamp-oldestTimestamp > c.lifeWindow { - evict(Expired) + evict() return true } return false @@ -188,15 +147,9 @@ func (c *BigCache) getShard(hashedKey uint64) (shard *cacheShard) { return c.shards[hashedKey&c.shardMask] } -func (c *BigCache) providedOnRemove(wrappedEntry []byte, reason RemoveReason) { +func (c *BigCache) providedOnRemove(wrappedEntry []byte) { c.config.OnRemove(readKeyFromEntry(wrappedEntry), readEntry(wrappedEntry)) } -func (c *BigCache) providedOnRemoveWithReason(wrappedEntry []byte, reason RemoveReason) { - if c.config.onRemoveFilter == 0 || (1< 0 { - c.config.OnRemoveWithReason(readKeyFromEntry(wrappedEntry), readEntry(wrappedEntry), reason) - } -} - -func (c *BigCache) notProvidedOnRemove(wrappedEntry []byte, reason RemoveReason) { +func (c *BigCache) notProvidedOnRemove(wrappedEntry []byte) { } diff --git a/vendor/github.com/allegro/bigcache/bytes.go b/vendor/github.com/allegro/bigcache/bytes.go deleted file mode 100644 index 3944bfe13..000000000 --- a/vendor/github.com/allegro/bigcache/bytes.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build !appengine - -package bigcache - -import ( - "reflect" - "unsafe" -) - -func bytesToString(b []byte) string { - bytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b)) - strHeader := reflect.StringHeader{Data: bytesHeader.Data, Len: bytesHeader.Len} - return *(*string)(unsafe.Pointer(&strHeader)) -} diff --git a/vendor/github.com/allegro/bigcache/bytes_appengine.go b/vendor/github.com/allegro/bigcache/bytes_appengine.go deleted file mode 100644 index 3892f3b54..000000000 --- a/vendor/github.com/allegro/bigcache/bytes_appengine.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build appengine - -package bigcache - -func bytesToString(b []byte) string { - return string(b) -} diff --git a/vendor/github.com/allegro/bigcache/config.go b/vendor/github.com/allegro/bigcache/config.go index 9654143ab..0a523947e 100644 --- a/vendor/github.com/allegro/bigcache/config.go +++ b/vendor/github.com/allegro/bigcache/config.go @@ -26,16 +26,8 @@ type Config struct { // the oldest entries are overridden for the new ones. HardMaxCacheSize int // OnRemove is a callback fired when the oldest entry is removed because of its expiration time or no space left - // for the new entry, or because delete was called. - // Default value is nil which means no callback and it prevents from unwrapping the oldest entry. + // for the new entry. Default value is nil which means no callback and it prevents from unwrapping the oldest entry. OnRemove func(key string, entry []byte) - // OnRemoveWithReason is a callback fired when the oldest entry is removed because of its expiration time or no space left - // for the new entry, or because delete was called. A constant representing the reason will be passed through. - // Default value is nil which means no callback and it prevents from unwrapping the oldest entry. - // Ignored if OnRemove is specified. - OnRemoveWithReason func(key string, entry []byte, reason RemoveReason) - - onRemoveFilter int // Logger is a logging interface and used in combination with `Verbose` // Defaults to `DefaultLogger()` @@ -73,14 +65,3 @@ func (c Config) maximumShardSize() int { return maxShardSize } - -// OnRemoveFilterSet sets which remove reasons will trigger a call to OnRemoveWithReason. -// Filtering out reasons prevents bigcache from unwrapping them, which saves cpu. -func (c Config) OnRemoveFilterSet(reasons ...RemoveReason) Config { - c.onRemoveFilter = 0 - for i := range reasons { - c.onRemoveFilter |= 1 << uint(reasons[i]) - } - - return c -} diff --git a/vendor/github.com/allegro/bigcache/encoding.go b/vendor/github.com/allegro/bigcache/encoding.go index 4d434e5dc..5d90d71d4 100644 --- a/vendor/github.com/allegro/bigcache/encoding.go +++ b/vendor/github.com/allegro/bigcache/encoding.go @@ -2,6 +2,8 @@ package bigcache import ( "encoding/binary" + "reflect" + "unsafe" ) const ( @@ -53,6 +55,12 @@ func readKeyFromEntry(data []byte) string { return bytesToString(dst) } +func bytesToString(b []byte) string { + bytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + strHeader := reflect.StringHeader{Data: bytesHeader.Data, Len: bytesHeader.Len} + return *(*string)(unsafe.Pointer(&strHeader)) +} + func readHashFromEntry(data []byte) uint64 { return binary.LittleEndian.Uint64(data[timestampSizeInBytes:]) } diff --git a/vendor/github.com/allegro/bigcache/entry_not_found_error.go b/vendor/github.com/allegro/bigcache/entry_not_found_error.go index 051a71230..e6955a57b 100644 --- a/vendor/github.com/allegro/bigcache/entry_not_found_error.go +++ b/vendor/github.com/allegro/bigcache/entry_not_found_error.go @@ -1,6 +1,17 @@ package bigcache -import "errors" +import "fmt" -// ErrEntryNotFound is an error type struct which is returned when entry was not found for provided key -var ErrEntryNotFound = errors.New("Entry not found") +// EntryNotFoundError is an error type struct which is returned when entry was not found for provided key +type EntryNotFoundError struct { + message string +} + +func notFound(key string) error { + return &EntryNotFoundError{fmt.Sprintf("Entry %q not found", key)} +} + +// Error returned when entry does not exist. +func (e EntryNotFoundError) Error() string { + return e.message +} diff --git a/vendor/github.com/allegro/bigcache/queue/bytes_queue.go b/vendor/github.com/allegro/bigcache/queue/bytes_queue.go index bda737403..0285c72cd 100644 --- a/vendor/github.com/allegro/bigcache/queue/bytes_queue.go +++ b/vendor/github.com/allegro/bigcache/queue/bytes_queue.go @@ -16,12 +16,6 @@ const ( minimumEmptyBlobSize = 32 + headerEntrySize ) -var ( - errEmptyQueue = &queueError{"Empty queue"} - errInvalidIndex = &queueError{"Index must be greater than zero. Invalid index."} - errIndexOutOfBounds = &queueError{"Index out of range"} -) - // BytesQueue is a non-thread safe queue type of fifo based on bytes array. // For every push operation index of entry is returned. It can be used to read the entry later type BytesQueue struct { @@ -168,11 +162,6 @@ func (q *BytesQueue) Get(index int) ([]byte, error) { return data, err } -// CheckGet checks if an entry can be read from index -func (q *BytesQueue) CheckGet(index int) error { - return q.peekCheckErr(index) -} - // Capacity returns number of allocated bytes for queue func (q *BytesQueue) Capacity() int { return q.capacity @@ -188,35 +177,18 @@ func (e *queueError) Error() string { return e.message } -// peekCheckErr is identical to peek, but does not actually return any data -func (q *BytesQueue) peekCheckErr(index int) error { - - if q.count == 0 { - return errEmptyQueue - } - - if index <= 0 { - return errInvalidIndex - } - - if index+headerEntrySize >= len(q.array) { - return errIndexOutOfBounds - } - return nil -} - func (q *BytesQueue) peek(index int) ([]byte, int, error) { if q.count == 0 { - return nil, 0, errEmptyQueue + return nil, 0, &queueError{"Empty queue"} } if index <= 0 { - return nil, 0, errInvalidIndex + return nil, 0, &queueError{"Index must be grater than zero. Invalid index."} } if index+headerEntrySize >= len(q.array) { - return nil, 0, errIndexOutOfBounds + return nil, 0, &queueError{"Index out of range"} } blockSize := int(binary.LittleEndian.Uint32(q.array[index : index+headerEntrySize])) diff --git a/vendor/github.com/allegro/bigcache/shard.go b/vendor/github.com/allegro/bigcache/shard.go index a31094ff3..af48ebc3b 100644 --- a/vendor/github.com/allegro/bigcache/shard.go +++ b/vendor/github.com/allegro/bigcache/shard.go @@ -8,14 +8,12 @@ import ( "github.com/allegro/bigcache/queue" ) -type onRemoveCallback func(wrappedEntry []byte, reason RemoveReason) - type cacheShard struct { hashmap map[uint64]uint32 entries queue.BytesQueue lock sync.RWMutex entryBuffer []byte - onRemove onRemoveCallback + onRemove func(wrappedEntry []byte) isVerbose bool logger Logger @@ -25,6 +23,8 @@ type cacheShard struct { stats Stats } +type onRemoveCallback func(wrappedEntry []byte) + func (s *cacheShard) get(key string, hashedKey uint64) ([]byte, error) { s.lock.RLock() itemIndex := s.hashmap[hashedKey] @@ -32,7 +32,7 @@ func (s *cacheShard) get(key string, hashedKey uint64) ([]byte, error) { if itemIndex == 0 { s.lock.RUnlock() s.miss() - return nil, ErrEntryNotFound + return nil, notFound(key) } wrappedEntry, err := s.entries.Get(int(itemIndex)) @@ -47,12 +47,11 @@ func (s *cacheShard) get(key string, hashedKey uint64) ([]byte, error) { } s.lock.RUnlock() s.collision() - return nil, ErrEntryNotFound + return nil, notFound(key) } - entry := readEntry(wrappedEntry) s.lock.RUnlock() s.hit() - return entry, nil + return readEntry(wrappedEntry), nil } func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error { @@ -78,7 +77,7 @@ func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error { s.lock.Unlock() return nil } - if s.removeOldestEntry(NoSpace) != nil { + if s.removeOldestEntry() != nil { s.lock.Unlock() return fmt.Errorf("entry is bigger than max shard size") } @@ -86,17 +85,17 @@ func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error { } func (s *cacheShard) del(key string, hashedKey uint64) error { - // Optimistic pre-check using only readlock s.lock.RLock() itemIndex := s.hashmap[hashedKey] if itemIndex == 0 { s.lock.RUnlock() s.delmiss() - return ErrEntryNotFound + return notFound(key) } - if err := s.entries.CheckGet(int(itemIndex)); err != nil { + wrappedEntry, err := s.entries.Get(int(itemIndex)) + if err != nil { s.lock.RUnlock() s.delmiss() return err @@ -105,25 +104,8 @@ func (s *cacheShard) del(key string, hashedKey uint64) error { s.lock.Lock() { - // After obtaining the writelock, we need to read the same again, - // since the data delivered earlier may be stale now - itemIndex = s.hashmap[hashedKey] - - if itemIndex == 0 { - s.lock.Unlock() - s.delmiss() - return ErrEntryNotFound - } - - wrappedEntry, err := s.entries.Get(int(itemIndex)) - if err != nil { - s.lock.Unlock() - s.delmiss() - return err - } - delete(s.hashmap, hashedKey) - s.onRemove(wrappedEntry, Deleted) + s.onRemove(wrappedEntry) resetKeyFromEntry(wrappedEntry) } s.lock.Unlock() @@ -132,10 +114,10 @@ func (s *cacheShard) del(key string, hashedKey uint64) error { return nil } -func (s *cacheShard) onEvict(oldestEntry []byte, currentTimestamp uint64, evict func(reason RemoveReason) error) bool { +func (s *cacheShard) onEvict(oldestEntry []byte, currentTimestamp uint64, evict func() error) bool { oldestTimestamp := readTimestampFromEntry(oldestEntry) if currentTimestamp-oldestTimestamp > s.lifeWindow { - evict(Expired) + evict() return true } return false @@ -154,23 +136,18 @@ func (s *cacheShard) cleanUp(currentTimestamp uint64) { } func (s *cacheShard) getOldestEntry() ([]byte, error) { - s.lock.RLock() - defer s.lock.RUnlock() return s.entries.Peek() } func (s *cacheShard) getEntry(index int) ([]byte, error) { - s.lock.RLock() - entry, err := s.entries.Get(index) - s.lock.RUnlock() - - return entry, err + return s.entries.Get(index) } func (s *cacheShard) copyKeys() (keys []uint32, next int) { - s.lock.RLock() keys = make([]uint32, len(s.hashmap)) + s.lock.RLock() + for _, index := range s.hashmap { keys[next] = index next++ @@ -180,12 +157,12 @@ func (s *cacheShard) copyKeys() (keys []uint32, next int) { return keys, next } -func (s *cacheShard) removeOldestEntry(reason RemoveReason) error { +func (s *cacheShard) removeOldestEntry() error { oldest, err := s.entries.Pop() if err == nil { hash := readHashFromEntry(oldest) delete(s.hashmap, hash) - s.onRemove(oldest, reason) + s.onRemove(oldest) return nil } return err @@ -206,13 +183,6 @@ func (s *cacheShard) len() int { return res } -func (s *cacheShard) capacity() int { - s.lock.RLock() - res := s.entries.Capacity() - s.lock.RUnlock() - return res -} - func (s *cacheShard) getStats() Stats { var stats = Stats{ Hits: atomic.LoadInt64(&s.stats.Hits), diff --git a/vendor/github.com/btcsuite/btcd/btcec/genprecomps.go b/vendor/github.com/btcsuite/btcd/btcec/genprecomps.go deleted file mode 100644 index d4a9c1b83..000000000 --- a/vendor/github.com/btcsuite/btcd/btcec/genprecomps.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// This file is ignored during the regular build due to the following build tag. -// It is called by go generate and used to automatically generate pre-computed -// tables used to accelerate operations. -// +build ignore - -package main - -import ( - "bytes" - "compress/zlib" - "encoding/base64" - "fmt" - "log" - "os" - - "github.com/btcsuite/btcd/btcec" -) - -func main() { - fi, err := os.Create("secp256k1.go") - if err != nil { - log.Fatal(err) - } - defer fi.Close() - - // Compress the serialized byte points. - serialized := btcec.S256().SerializedBytePoints() - var compressed bytes.Buffer - w := zlib.NewWriter(&compressed) - if _, err := w.Write(serialized); err != nil { - fmt.Println(err) - os.Exit(1) - } - w.Close() - - // Encode the compressed byte points with base64. - encoded := make([]byte, base64.StdEncoding.EncodedLen(compressed.Len())) - base64.StdEncoding.Encode(encoded, compressed.Bytes()) - - fmt.Fprintln(fi, "// Copyright (c) 2015 The btcsuite developers") - fmt.Fprintln(fi, "// Use of this source code is governed by an ISC") - fmt.Fprintln(fi, "// license that can be found in the LICENSE file.") - fmt.Fprintln(fi) - fmt.Fprintln(fi, "package btcec") - fmt.Fprintln(fi) - fmt.Fprintln(fi, "// Auto-generated file (see genprecomps.go)") - fmt.Fprintln(fi, "// DO NOT EDIT") - fmt.Fprintln(fi) - fmt.Fprintf(fi, "var secp256k1BytePoints = %q\n", string(encoded)) - - a1, b1, a2, b2 := btcec.S256().EndomorphismVectors() - fmt.Println("The following values are the computed linearly " + - "independent vectors needed to make use of the secp256k1 " + - "endomorphism:") - fmt.Printf("a1: %x\n", a1) - fmt.Printf("b1: %x\n", b1) - fmt.Printf("a2: %x\n", a2) - fmt.Printf("b2: %x\n", b2) -} diff --git a/vendor/github.com/btcsuite/btcutil/base58/genalphabet.go b/vendor/github.com/btcsuite/btcutil/base58/genalphabet.go deleted file mode 100644 index 010cbee39..000000000 --- a/vendor/github.com/btcsuite/btcutil/base58/genalphabet.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -//+build ignore - -package main - -import ( - "bytes" - "io" - "log" - "os" - "strconv" -) - -var ( - start = []byte(`// Copyright (c) 2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// AUTOGENERATED by genalphabet.go; do not edit. - -package base58 - -const ( - // alphabet is the modified base58 alphabet used by Bitcoin. - alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" - - alphabetIdx0 = '1' -) - -var b58 = [256]byte{`) - - end = []byte(`}`) - - alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") - tab = []byte("\t") - invalid = []byte("255") - comma = []byte(",") - space = []byte(" ") - nl = []byte("\n") -) - -func write(w io.Writer, b []byte) { - _, err := w.Write(b) - if err != nil { - log.Fatal(err) - } -} - -func main() { - fi, err := os.Create("alphabet.go") - if err != nil { - log.Fatal(err) - } - defer fi.Close() - - write(fi, start) - write(fi, nl) - for i := byte(0); i < 32; i++ { - write(fi, tab) - for j := byte(0); j < 8; j++ { - idx := bytes.IndexByte(alphabet, i*8+j) - if idx == -1 { - write(fi, invalid) - } else { - write(fi, strconv.AppendInt(nil, int64(idx), 10)) - } - write(fi, comma) - if j != 7 { - write(fi, space) - } - } - write(fi, nl) - } - write(fi, end) - write(fi, nl) -} diff --git a/vendor/github.com/lib/pq/oid/gen.go b/vendor/github.com/lib/pq/oid/gen.go deleted file mode 100644 index 7c634cdc5..000000000 --- a/vendor/github.com/lib/pq/oid/gen.go +++ /dev/null @@ -1,93 +0,0 @@ -// +build ignore - -// Generate the table of OID values -// Run with 'go run gen.go'. -package main - -import ( - "database/sql" - "fmt" - "log" - "os" - "os/exec" - "strings" - - _ "github.com/lib/pq" -) - -// OID represent a postgres Object Identifier Type. -type OID struct { - ID int - Type string -} - -// Name returns an upper case version of the oid type. -func (o OID) Name() string { - return strings.ToUpper(o.Type) -} - -func main() { - datname := os.Getenv("PGDATABASE") - sslmode := os.Getenv("PGSSLMODE") - - if datname == "" { - os.Setenv("PGDATABASE", "pqgotest") - } - - if sslmode == "" { - os.Setenv("PGSSLMODE", "disable") - } - - db, err := sql.Open("postgres", "") - if err != nil { - log.Fatal(err) - } - rows, err := db.Query(` - SELECT typname, oid - FROM pg_type WHERE oid < 10000 - ORDER BY oid; - `) - if err != nil { - log.Fatal(err) - } - oids := make([]*OID, 0) - for rows.Next() { - var oid OID - if err = rows.Scan(&oid.Type, &oid.ID); err != nil { - log.Fatal(err) - } - oids = append(oids, &oid) - } - if err = rows.Err(); err != nil { - log.Fatal(err) - } - cmd := exec.Command("gofmt") - cmd.Stderr = os.Stderr - w, err := cmd.StdinPipe() - if err != nil { - log.Fatal(err) - } - f, err := os.Create("types.go") - if err != nil { - log.Fatal(err) - } - cmd.Stdout = f - err = cmd.Start() - if err != nil { - log.Fatal(err) - } - fmt.Fprintln(w, "// Code generated by gen.go. DO NOT EDIT.") - fmt.Fprintln(w, "\npackage oid") - fmt.Fprintln(w, "const (") - for _, oid := range oids { - fmt.Fprintf(w, "T_%s Oid = %d\n", oid.Type, oid.ID) - } - fmt.Fprintln(w, ")") - fmt.Fprintln(w, "var TypeName = map[Oid]string{") - for _, oid := range oids { - fmt.Fprintf(w, "T_%s: \"%s\",\n", oid.Type, oid.Name()) - } - fmt.Fprintln(w, "}") - w.Close() - cmd.Wait() -} diff --git a/vendor/github.com/status-im/status-protocol-go/.travis.yml b/vendor/github.com/status-im/status-protocol-go/.travis.yml index 22022eab3..7add15736 100644 --- a/vendor/github.com/status-im/status-protocol-go/.travis.yml +++ b/vendor/github.com/status-im/status-protocol-go/.travis.yml @@ -4,17 +4,13 @@ notifications: language: go go: - "1.12.x" - - "1.13beta1" + - "1.13.x" install: true env: - GO111MODULE=on GOFLAGS=-mod=vendor -matrix: - allow_failures: - - go: "1.13beta1" - before_script: - make install-linter diff --git a/vendor/github.com/status-im/status-protocol-go/Makefile b/vendor/github.com/status-im/status-protocol-go/Makefile index 1673d50cb..e473965fa 100644 --- a/vendor/github.com/status-im/status-protocol-go/Makefile +++ b/vendor/github.com/status-im/status-protocol-go/Makefile @@ -24,7 +24,7 @@ vendor: install-linter: # install linter - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.17.1 + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.19.0 .PHONY: install-linter install-dev: diff --git a/vendor/github.com/status-im/status-protocol-go/chat.go b/vendor/github.com/status-im/status-protocol-go/chat.go index ae0e27952..70531a1f8 100644 --- a/vendor/github.com/status-im/status-protocol-go/chat.go +++ b/vendor/github.com/status-im/status-protocol-go/chat.go @@ -3,19 +3,15 @@ package statusproto import ( "crypto/ecdsa" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" + "github.com/google/uuid" + statusproto "github.com/status-im/status-protocol-go/types" ) -type ChatPagination struct { - From uint - To uint -} - type ChatType int const ( - ChatTypeOneToOne = iota + 1 + ChatTypeOneToOne ChatType = iota + 1 ChatTypePublic ChatTypePrivateGroupChat ) @@ -87,7 +83,7 @@ type ChatMember struct { } func (c ChatMember) PublicKey() (*ecdsa.PublicKey, error) { - b, err := hexutil.Decode(c.ID) + b, err := statusproto.DecodeHex(c.ID) if err != nil { return nil, err } @@ -95,7 +91,7 @@ func (c ChatMember) PublicKey() (*ecdsa.PublicKey, error) { } func oneToOneChatID(publicKey *ecdsa.PublicKey) string { - return hexutil.Encode(crypto.FromECDSAPub(publicKey)) + return statusproto.EncodeHex(crypto.FromECDSAPub(publicKey)) } func CreateOneToOneChat(name string, publicKey *ecdsa.PublicKey) Chat { @@ -117,6 +113,19 @@ func CreatePublicChat(name string) Chat { } } +func groupChatID(creator *ecdsa.PublicKey) string { + return uuid.New().String() + statusproto.EncodeHex(crypto.FromECDSAPub(creator)) +} + +func CreateGroupChat(name string, creator *ecdsa.PublicKey) Chat { + return Chat{ + ID: groupChatID(creator), + Name: name, + Active: true, + ChatType: ChatTypePrivateGroupChat, + } +} + func findChatByID(chatID string, chats []*Chat) *Chat { for _, c := range chats { if c.ID == chatID { diff --git a/vendor/github.com/status-im/status-protocol-go/contact.go b/vendor/github.com/status-im/status-protocol-go/contact.go index 44e1b0bd9..86f4f153f 100644 --- a/vendor/github.com/status-im/status-protocol-go/contact.go +++ b/vendor/github.com/status-im/status-protocol-go/contact.go @@ -3,8 +3,8 @@ package statusproto import ( "crypto/ecdsa" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" + statusproto "github.com/status-im/status-protocol-go/types" ) const ( @@ -50,7 +50,7 @@ type Contact struct { } func (c Contact) PublicKey() (*ecdsa.PublicKey, error) { - b, err := hexutil.Decode(c.ID) + b, err := statusproto.DecodeHex(c.ID) if err != nil { return nil, err } diff --git a/vendor/github.com/status-im/status-protocol-go/crypto/crypto.go b/vendor/github.com/status-im/status-protocol-go/crypto/crypto.go index f650e2c7f..f54f05b99 100644 --- a/vendor/github.com/status-im/status-protocol-go/crypto/crypto.go +++ b/vendor/github.com/status-im/status-protocol-go/crypto/crypto.go @@ -16,17 +16,32 @@ const ( aesNonceLength = 12 ) -// Sign signs the hash of an arbitrary string -func Sign(content string, identity *ecdsa.PrivateKey) (string, error) { - signature, err := crypto.Sign(crypto.Keccak256([]byte(content)), identity) +// SignBytes signs the hash of arbitrary data. +func SignBytes(data []byte, identity *ecdsa.PrivateKey) ([]byte, error) { + return crypto.Sign(crypto.Keccak256(data), identity) +} + +// SignStringAsHex signs the Keccak256 hash of arbitrary data and returns its hex representation. +func SignBytesAsHex(data []byte, identity *ecdsa.PrivateKey) (string, error) { + signature, err := SignBytes(data, identity) if err != nil { return "", err } - return hex.EncodeToString(signature), nil } -// VerifySignatures verifys tuples of signatures content/hash/public key +// SignStringAsHex signs the Keccak256 hash of arbitrary string and returns its hex representation. +func SignStringAsHex(data string, identity *ecdsa.PrivateKey) (string, error) { + return SignBytesAsHex([]byte(data), identity) +} + +// Sign signs the hash of arbitrary data. +// DEPRECATED: use SignStringAsHex instead. +func Sign(data string, identity *ecdsa.PrivateKey) (string, error) { + return SignStringAsHex(data, identity) +} + +// VerifySignatures verifies tuples of signatures content/hash/public key func VerifySignatures(signaturePairs [][3]string) error { for _, signaturePair := range signaturePairs { content := crypto.Keccak256([]byte(signaturePair[0])) diff --git a/vendor/github.com/status-im/status-protocol-go/go.mod b/vendor/github.com/status-im/status-protocol-go/go.mod index c19eca473..54e9504c2 100644 --- a/vendor/github.com/status-im/status-protocol-go/go.mod +++ b/vendor/github.com/status-im/status-protocol-go/go.mod @@ -5,22 +5,19 @@ go 1.12 require ( github.com/aristanetworks/goarista v0.0.0-20190704150520-f44d68189fd7 // indirect github.com/cenkalti/backoff/v3 v3.0.0 - github.com/deckarep/golang-set v1.7.1 // indirect - github.com/ethereum/go-ethereum v1.8.27 + github.com/ethereum/go-ethereum v1.9.5 github.com/golang/protobuf v1.3.2 + github.com/google/uuid v1.1.1 github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8 github.com/lucasb-eyer/go-colorful v1.0.2 github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f - github.com/onsi/ginkgo v1.8.0 // indirect - github.com/onsi/gomega v1.5.0 // indirect github.com/pkg/errors v0.8.1 - github.com/rs/cors v1.6.0 // indirect github.com/russolsen/ohyeah v0.0.0-20160324131710-f4938c005315 // indirect github.com/russolsen/same v0.0.0-20160222130632-f089df61f51d // indirect github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a github.com/status-im/doubleratchet v2.0.0+incompatible github.com/status-im/migrate/v4 v4.0.0-20190821140204-a9d340ec8fb76af4afda06acf01740d45d2661ed - github.com/status-im/whisper v1.4.14 + github.com/status-im/whisper v1.5.1 github.com/stretchr/testify v1.3.1-0.20190712000136-221dbe5ed467 github.com/vacp2p/mvds v0.0.21 go.uber.org/zap v1.10.0 @@ -29,4 +26,4 @@ require ( golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 // indirect ) -replace github.com/ethereum/go-ethereum v1.8.27 => github.com/status-im/go-ethereum v1.8.27-status.4 +replace github.com/ethereum/go-ethereum v1.9.5 => github.com/status-im/go-ethereum v1.9.5-status.4 diff --git a/vendor/github.com/status-im/status-protocol-go/go.sum b/vendor/github.com/status-im/status-protocol-go/go.sum index 4ab71d4fe..e5b0c0aae 100644 --- a/vendor/github.com/status-im/status-protocol-go/go.sum +++ b/vendor/github.com/status-im/status-protocol-go/go.sum @@ -16,13 +16,16 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/allegro/bigcache v0.0.0-20190218064605-e24eb225f156 h1:hh7BAWFHv41r0gce0KRYtDJpL4erKfmB1/mpgoSADeI= github.com/allegro/bigcache v0.0.0-20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/allegro/bigcache v1.1.0/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= +github.com/aristanetworks/goarista v0.0.0-20181002214814-33151c4543a7/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/aristanetworks/goarista v0.0.0-20190704150520-f44d68189fd7 h1:fKnuvQ/O22ZpD7HaJjGQXn/GxOdDJOQFL8bpM8Xe3X8= github.com/aristanetworks/goarista v0.0.0-20190704150520-f44d68189fd7/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/aws/aws-sdk-go v1.17.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= @@ -32,6 +35,8 @@ github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCS github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6 h1:Eey/GGQ/E5Xp1P2Lyx1qj007hLZfbi0+CoVeJruGCtI= github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= +github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac h1:/zx+Hglw2JN/pwVam1Z8cTCTl4pWyrbvOn2oooqCQSs= +github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= @@ -74,6 +79,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= +github.com/elastic/gosigar v0.0.0-20180330100440-37f05ff46ffa h1:o8OuEkracbk3qH6GvlI6XpEN1HTSxkzOG42xZpfDv/s= github.com/elastic/gosigar v0.0.0-20180330100440-37f05ff46ffa/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= @@ -83,6 +89,7 @@ github.com/fsouza/fake-gcs-server v1.7.0/go.mod h1:5XIRs4YvwNbNoz+1JF8j6KLAyDh7R github.com/gizak/termui v0.0.0-20170117222342-991cd3d38091/go.mod h1:PkJoWUt/zacQKysNfQtcw1RW+eK2SxkieVBtl+4ovLA= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.5.4/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -117,11 +124,15 @@ github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+u github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU= github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -134,11 +145,16 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3 h1:DqD8eigqlUm0+znmx7zhL0xvTW3+e1jCekJMfBUADWI= github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag= +github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= +github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= +github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/influxdata/influxdb v0.0.0-20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ= github.com/jackc/pgx v3.2.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jackpal/go-nat-pmp v0.0.0-20160603034137-1fa385a6f458 h1:LPECOO5LcZx5tvkxraIptrg6AiAUf+28rFV9+noSZFA= github.com/jackpal/go-nat-pmp v0.0.0-20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= +github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8 h1:mGIXW/lubQ4B+3bXTLxcTMTjUNDqoF6T/HUW9LbFx9s= github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -183,11 +199,11 @@ github.com/nsf/termbox-go v0.0.0-20170211012700-3540b76b9c77/go.mod h1:IuKpRQcYE github.com/olekukonko/tablewriter v0.0.0-20170128050532-febf2d34b54a/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= -github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= +github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= -github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= @@ -237,12 +253,14 @@ github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/status-im/doubleratchet v2.0.0+incompatible h1:s77lF1lDubK0RKftxN2vH8G9gwtVVp13ggWfyY4O1q4= github.com/status-im/doubleratchet v2.0.0+incompatible/go.mod h1:1sqR0+yhiM/bd+wrdX79AOt2csZuJOni0nUDzKNuqOU= -github.com/status-im/go-ethereum v1.8.27-status.4 h1:8jTQsYDLtKd/XCa++ZkexTPHfANIDh084JbO2SBAwp4= -github.com/status-im/go-ethereum v1.8.27-status.4/go.mod h1:Ulij8LMpMvXnbnPcmDqrpI+iXoXSjxItuY/wmbasTZU= +github.com/status-im/go-ethereum v1.9.5-status.4 h1:F5VrxH9LmTxWl4qwQjs0TI5TgG9dVuZKqGmdwHJ0cWk= +github.com/status-im/go-ethereum v1.9.5-status.4/go.mod h1:Ulij8LMpMvXnbnPcmDqrpI+iXoXSjxItuY/wmbasTZU= github.com/status-im/migrate/v4 v4.0.0-20190821140204-a9d340ec8fb76af4afda06acf01740d45d2661ed h1:K2iga8l8OQIHnk2bBq2QsZTO2Q38YWy04xIspdITCdM= github.com/status-im/migrate/v4 v4.0.0-20190821140204-a9d340ec8fb76af4afda06acf01740d45d2661ed/go.mod h1:r8HggRBZ/k7TRwByq/Hp3P/ubFppIna0nvyavVK0pjA= -github.com/status-im/whisper v1.4.14 h1:9VHqx4+PUYfhDnYYtDxHkg/3cfVvkHjPNciY4LO83yc= -github.com/status-im/whisper v1.4.14/go.mod h1:WS6z39YJQ8WJa9s+DmTuEM/s2nVF6Iz3B1SZYw5cYf0= +github.com/status-im/whisper v1.5.1 h1:87/XIg0Wjua7lXBGiEXgAfTOqlt2Q1dMDuxugTyZbbA= +github.com/status-im/whisper v1.5.1/go.mod h1:emrOxzJme0k66QtbbQ2bdd3P8RCdLZ8sTD7SkwH1s2s= +github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= +github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= @@ -288,6 +306,7 @@ golang.org/x/net v0.0.0-20180112015858-5ccada7d0a7b/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/vendor/github.com/status-im/status-protocol-go/identity/identicon/renderer.go b/vendor/github.com/status-im/status-protocol-go/identity/identicon/renderer.go index 4a7db0bcf..368f992ea 100644 --- a/vendor/github.com/status-im/status-protocol-go/identity/identicon/renderer.go +++ b/vendor/github.com/status-im/status-protocol-go/identity/identicon/renderer.go @@ -31,7 +31,7 @@ func renderBase64(id Identicon) (string, error) { } func setBackgroundWhite(img *image.RGBA) { - draw.Draw(img, img.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src) + draw.Draw(img, img.Bounds(), &image.Uniform{C: color.White}, image.Point{}, draw.Src) } func drawRect(rgba *image.RGBA, i int, c color.Color) { @@ -45,7 +45,7 @@ func drawRect(rgba *image.RGBA, i int, c color.Color) { 10+(i/maxRow)*sizeSquare+sizeSquare, ) - draw.Draw(rgba, r, &image.Uniform{c}, image.ZP, draw.Src) + draw.Draw(rgba, r, &image.Uniform{C: c}, image.Point{}, draw.Src) } // GenerateBase64 generates an identicon in base64 png format given a string diff --git a/vendor/github.com/status-im/status-protocol-go/message.go b/vendor/github.com/status-im/status-protocol-go/message.go index 923a315be..ea1fb8ff7 100644 --- a/vendor/github.com/status-im/status-protocol-go/message.go +++ b/vendor/github.com/status-im/status-protocol-go/message.go @@ -3,18 +3,18 @@ package statusproto import ( "database/sql/driver" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" + statusproto "github.com/status-im/status-protocol-go/types" ) -type hexutilSQL hexutil.Bytes +type hexutilSQL statusproto.HexBytes func (h hexutilSQL) Value() (driver.Value, error) { return []byte(h), nil } func (h hexutilSQL) String() string { - return hexutil.Encode(h) + return statusproto.EncodeHex(h) } func (h *hexutilSQL) Scan(value interface{}) error { diff --git a/vendor/github.com/status-im/status-protocol-go/message_processor.go b/vendor/github.com/status-im/status-protocol-go/message_processor.go index 5ac2ba159..bd3cca413 100644 --- a/vendor/github.com/status-im/status-protocol-go/message_processor.go +++ b/vendor/github.com/status-im/status-protocol-go/message_processor.go @@ -14,8 +14,8 @@ import ( "github.com/status-im/status-protocol-go/encryption" "github.com/status-im/status-protocol-go/encryption/multidevice" transport "github.com/status-im/status-protocol-go/transport/whisper" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" protocol "github.com/status-im/status-protocol-go/v1" - whisper "github.com/status-im/whisper/whisperv6" datasyncnode "github.com/vacp2p/mvds/node" datasyncproto "github.com/vacp2p/mvds/protobuf" "go.uber.org/zap" @@ -155,7 +155,7 @@ func (p *messageProcessor) sendPrivate( return nil, errors.Wrap(err, "failed to send a message spec") } - p.transport.Track([][]byte{messageID}, hash, *newMessage) + p.transport.Track([][]byte{messageID}, hash, newMessage) } return messageID, nil @@ -187,7 +187,7 @@ func (p *messageProcessor) SendPublic(ctx context.Context, chatID string, data [ return nil, err } - hash, err := p.transport.SendPublic(ctx, &newMessage, chatID) + hash, err := p.transport.SendPublic(ctx, newMessage, chatID) if err != nil { return nil, err } @@ -201,21 +201,21 @@ func (p *messageProcessor) SendPublic(ctx context.Context, chatID string, data [ // SendPublicRaw takes encoded data, encrypts it and sends through the wire. func (p *messageProcessor) SendPublicRaw(ctx context.Context, chatName string, data []byte) ([]byte, error) { - var newMessage whisper.NewMessage + var newMessage *whispertypes.NewMessage wrappedMessage, err := p.tryWrapMessageV1(data) if err != nil { return nil, errors.Wrap(err, "failed to wrap message") } - newMessage = whisper.NewMessage{ + newMessage = &whispertypes.NewMessage{ TTL: whisperTTL, Payload: wrappedMessage, PowTarget: whisperPoW, PowTime: whisperPoWTime, } - hash, err := p.transport.SendPublic(ctx, &newMessage, chatName) + hash, err := p.transport.SendPublic(ctx, newMessage, chatName) if err != nil { return nil, err } @@ -230,13 +230,11 @@ func (p *messageProcessor) SendPublicRaw(ctx context.Context, chatName string, d // Process processes received Whisper messages through all the layers // and returns decoded user messages. // It also handled all non-user messages like PairMessage. -func (p *messageProcessor) Process(message *whisper.ReceivedMessage) ([]*protocol.Message, error) { +func (p *messageProcessor) Process(shhMessage *whispertypes.Message) ([]*protocol.Message, error) { logger := p.logger.With(zap.String("site", "Process")) var decodedMessages []*protocol.Message - shhMessage := whisper.ToWhisperMessage(message) - hlogger := logger.With(zap.Binary("hash", shhMessage.Hash)) hlogger.Debug("handling a received message") @@ -283,7 +281,7 @@ func (p *messageProcessor) processPairMessage(m protocol.PairMessage) error { // layer message, or in case of Raw methods, the processing stops at the layer // before. // It returns an error only if the processing of required steps failed. -func (p *messageProcessor) handleMessages(shhMessage *whisper.Message, applicationLayer bool) ([]*protocol.StatusMessage, error) { +func (p *messageProcessor) handleMessages(shhMessage *whispertypes.Message, applicationLayer bool) ([]*protocol.StatusMessage, error) { logger := p.logger.With(zap.String("site", "handleMessages")) hlogger := logger.With(zap.Binary("hash", shhMessage.Hash)) var statusMessage protocol.StatusMessage @@ -423,13 +421,13 @@ func (p *messageProcessor) sendDataSync(ctx context.Context, publicKey *ecdsa.Pu return err } - p.transport.Track(messageIDs, hash, *newMessage) + p.transport.Track(messageIDs, hash, newMessage) return nil } // sendMessageSpec analyses the spec properties and selects a proper transport method. -func (p *messageProcessor) sendMessageSpec(ctx context.Context, publicKey *ecdsa.PublicKey, messageSpec *encryption.ProtocolMessageSpec) ([]byte, *whisper.NewMessage, error) { +func (p *messageProcessor) sendMessageSpec(ctx context.Context, publicKey *ecdsa.PublicKey, messageSpec *encryption.ProtocolMessageSpec) ([]byte, *whispertypes.NewMessage, error) { newMessage, err := messageSpecToWhisper(messageSpec) if err != nil { return nil, nil, err @@ -442,33 +440,33 @@ func (p *messageProcessor) sendMessageSpec(ctx context.Context, publicKey *ecdsa switch { case messageSpec.SharedSecret != nil: logger.Debug("sending using shared secret") - hash, err = p.transport.SendPrivateWithSharedSecret(ctx, &newMessage, publicKey, messageSpec.SharedSecret) + hash, err = p.transport.SendPrivateWithSharedSecret(ctx, newMessage, publicKey, messageSpec.SharedSecret) case messageSpec.PartitionedTopicMode() == encryption.PartitionTopicV1: logger.Debug("sending partitioned topic") - hash, err = p.transport.SendPrivateWithPartitioned(ctx, &newMessage, publicKey) + hash, err = p.transport.SendPrivateWithPartitioned(ctx, newMessage, publicKey) case !p.featureFlags.genericDiscoveryTopicEnabled: logger.Debug("sending partitioned topic (generic discovery topic disabled)") - hash, err = p.transport.SendPrivateWithPartitioned(ctx, &newMessage, publicKey) + hash, err = p.transport.SendPrivateWithPartitioned(ctx, newMessage, publicKey) default: logger.Debug("sending using discovery topic") - hash, err = p.transport.SendPrivateOnDiscovery(ctx, &newMessage, publicKey) + hash, err = p.transport.SendPrivateOnDiscovery(ctx, newMessage, publicKey) } if err != nil { return nil, nil, err } - return hash, &newMessage, nil + return hash, newMessage, nil } -func messageSpecToWhisper(spec *encryption.ProtocolMessageSpec) (whisper.NewMessage, error) { - var newMessage whisper.NewMessage +func messageSpecToWhisper(spec *encryption.ProtocolMessageSpec) (*whispertypes.NewMessage, error) { + var newMessage *whispertypes.NewMessage payload, err := proto.Marshal(spec.Message) if err != nil { return newMessage, err } - newMessage = whisper.NewMessage{ + newMessage = &whispertypes.NewMessage{ TTL: whisperTTL, Payload: payload, PowTarget: whisperPoW, diff --git a/vendor/github.com/status-im/status-protocol-go/messenger.go b/vendor/github.com/status-im/status-protocol-go/messenger.go index 29862945b..db8416cd2 100644 --- a/vendor/github.com/status-im/status-protocol-go/messenger.go +++ b/vendor/github.com/status-im/status-protocol-go/messenger.go @@ -9,10 +9,8 @@ import ( "strings" "time" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/pkg/errors" - whisper "github.com/status-im/whisper/whisperv6" "go.uber.org/zap" "github.com/status-im/status-protocol-go/encryption" @@ -22,6 +20,8 @@ import ( "github.com/status-im/status-protocol-go/identity/identicon" "github.com/status-im/status-protocol-go/sqlite" transport "github.com/status-im/status-protocol-go/transport/whisper" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" protocol "github.com/status-im/status-protocol-go/v1" ) @@ -169,7 +169,7 @@ func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option { func NewMessenger( identity *ecdsa.PrivateKey, - shh *whisper.Whisper, + shh whispertypes.Whisper, installationID string, opts ...Option, ) (*Messenger, error) { @@ -228,7 +228,7 @@ func NewMessenger( ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() chatName := transport.ContactCodeTopic(&messenger.identity.PublicKey) - _, err = messenger.transport.SendPublic(ctx, &newMessage, chatName) + _, err = messenger.transport.SendPublic(ctx, newMessage, chatName) if err != nil { slogger.Warn("failed to send a contact code", zap.Error(err)) } @@ -404,7 +404,7 @@ func (m *Messenger) handleSharedSecrets(secrets []*sharedsecret.Secret) ([]*tran var result []*transport.Filter for _, secret := range secrets { logger.Debug("received shared secret", zap.Binary("identity", crypto.FromECDSAPub(secret.Identity))) - fSecret := transport.NegotiatedSecret{ + fSecret := whispertypes.NegotiatedSecret{ PublicKey: secret.Identity, Key: secret.Key, } @@ -627,7 +627,7 @@ func (m *Messenger) retrieveLatest(ctx context.Context) ([]*protocol.Message, er return nil, errors.Wrap(err, "failed to retrieve messages") } - logger := m.logger.With(zap.String("site", "RetrieveAll")) + logger := m.logger.With(zap.String("site", "retrieveLatest")) logger.Debug("retrieved messages", zap.Int("count", len(latest))) var result []*protocol.Message @@ -670,8 +670,7 @@ func (m *Messenger) RetrieveRawAll() (map[transport.Filter][]*protocol.StatusMes result := make(map[transport.Filter][]*protocol.StatusMessage) for chat, messages := range chatWithMessages { - for _, message := range messages { - shhMessage := whisper.ToWhisperMessage(message) + for _, shhMessage := range messages { // TODO: fix this to use an exported method. statusMessages, err := m.processor.handleMessages(shhMessage, false) if err != nil { @@ -889,7 +888,7 @@ func (p *postProcessor) matchMessage(message *protocol.Message, chats []*Chat) ( case message.MessageT == protocol.MessageTypePrivate: // It's an incoming private message. ChatID is calculated from the signature. // If a chat does not exist, a new one is created and saved. - chatID := hexutil.Encode(crypto.FromECDSAPub(message.SigPubKey)) + chatID := statusproto.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) chat := findChatByID(chatID, chats) if chat == nil { // TODO: this should be a three-word name used in the mobile client @@ -905,7 +904,7 @@ func (p *postProcessor) matchMessage(message *protocol.Message, chats []*Chat) ( // It needs to be verified if the signature public key belongs to the chat. chatID := message.Content.ChatID chat := findChatByID(chatID, chats) - sigPubKeyHex := hexutil.Encode(crypto.FromECDSAPub(message.SigPubKey)) + sigPubKeyHex := statusproto.EncodeHex(crypto.FromECDSAPub(message.SigPubKey)) for _, member := range chat.Members { if member.ID == sigPubKeyHex { return chat, nil diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/envelopes.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/envelopes.go index f4294b42d..f1dff1141 100644 --- a/vendor/github.com/status-im/status-protocol-go/transport/whisper/envelopes.go +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/envelopes.go @@ -5,9 +5,8 @@ import ( "errors" "sync" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/p2p/enode" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" "go.uber.org/zap" ) @@ -27,7 +26,7 @@ type EnvelopesMonitorConfig struct { EnvelopeEventsHandler EnvelopeEventsHandler MaxAttempts int MailserverConfirmationsEnabled bool - IsMailserver func(enode.ID) bool + IsMailserver func(whispertypes.EnodeID) bool Logger *zap.Logger } @@ -35,21 +34,26 @@ type EnvelopesMonitorConfig struct { type EnvelopeEventsHandler interface { EnvelopeSent([][]byte) EnvelopeExpired([][]byte, error) - MailServerRequestCompleted(common.Hash, common.Hash, []byte, error) - MailServerRequestExpired(common.Hash) + MailServerRequestCompleted(statusproto.Hash, statusproto.Hash, []byte, error) + MailServerRequestExpired(statusproto.Hash) } // NewEnvelopesMonitor returns a pointer to an instance of the EnvelopesMonitor. -func NewEnvelopesMonitor(w *whisper.Whisper, config *EnvelopesMonitorConfig) *EnvelopesMonitor { +func NewEnvelopesMonitor(w whispertypes.Whisper, config EnvelopesMonitorConfig) *EnvelopesMonitor { logger := config.Logger if logger == nil { logger = zap.NewNop() } + var whisperAPI whispertypes.PublicWhisperAPI + if w != nil { + whisperAPI = w.PublicWhisperAPI() + } + return &EnvelopesMonitor{ w: w, - whisperAPI: whisper.NewPublicWhisperAPI(w), + whisperAPI: whisperAPI, handler: config.EnvelopeEventsHandler, mailServerConfirmation: config.MailserverConfirmationsEnabled, maxAttempts: config.MaxAttempts, @@ -57,35 +61,35 @@ func NewEnvelopesMonitor(w *whisper.Whisper, config *EnvelopesMonitorConfig) *En logger: logger.With(zap.Namespace("EnvelopesMonitor")), // key is envelope hash (event.Hash) - envelopes: map[common.Hash]EnvelopeState{}, - messages: map[common.Hash]whisper.NewMessage{}, - attempts: map[common.Hash]int{}, - identifiers: make(map[common.Hash][][]byte), + envelopes: map[statusproto.Hash]EnvelopeState{}, + messages: map[statusproto.Hash]*whispertypes.NewMessage{}, + attempts: map[statusproto.Hash]int{}, + identifiers: make(map[statusproto.Hash][][]byte), // key is hash of the batch (event.Batch) - batches: map[common.Hash]map[common.Hash]struct{}{}, + batches: map[statusproto.Hash]map[statusproto.Hash]struct{}{}, } } // EnvelopesMonitor is responsible for monitoring whisper envelopes state. type EnvelopesMonitor struct { - w *whisper.Whisper - whisperAPI *whisper.PublicWhisperAPI + w whispertypes.Whisper + whisperAPI whispertypes.PublicWhisperAPI handler EnvelopeEventsHandler mailServerConfirmation bool maxAttempts int mu sync.Mutex - envelopes map[common.Hash]EnvelopeState - batches map[common.Hash]map[common.Hash]struct{} + envelopes map[statusproto.Hash]EnvelopeState + batches map[statusproto.Hash]map[statusproto.Hash]struct{} - messages map[common.Hash]whisper.NewMessage - attempts map[common.Hash]int - identifiers map[common.Hash][][]byte + messages map[statusproto.Hash]*whispertypes.NewMessage + attempts map[statusproto.Hash]int + identifiers map[statusproto.Hash][][]byte wg sync.WaitGroup quit chan struct{} - isMailserver func(peer enode.ID) bool + isMailserver func(peer whispertypes.EnodeID) bool logger *zap.Logger } @@ -107,16 +111,16 @@ func (m *EnvelopesMonitor) Stop() { } // Add hash to a tracker. -func (m *EnvelopesMonitor) Add(identifiers [][]byte, envelopeHash common.Hash, message whisper.NewMessage) { +func (m *EnvelopesMonitor) Add(identifiers [][]byte, envelopeHash statusproto.Hash, message whispertypes.NewMessage) { m.mu.Lock() defer m.mu.Unlock() m.envelopes[envelopeHash] = EnvelopePosted m.identifiers[envelopeHash] = identifiers - m.messages[envelopeHash] = message + m.messages[envelopeHash] = &message m.attempts[envelopeHash] = 1 } -func (m *EnvelopesMonitor) GetState(hash common.Hash) EnvelopeState { +func (m *EnvelopesMonitor) GetState(hash statusproto.Hash) EnvelopeState { m.mu.Lock() defer m.mu.Unlock() state, exist := m.envelopes[hash] @@ -128,13 +132,18 @@ func (m *EnvelopesMonitor) GetState(hash common.Hash) EnvelopeState { // handleEnvelopeEvents processes whisper envelope events func (m *EnvelopesMonitor) handleEnvelopeEvents() { - events := make(chan whisper.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper + events := make(chan whispertypes.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper sub := m.w.SubscribeEnvelopeEvents(events) - defer sub.Unsubscribe() + defer func() { + close(events) + sub.Unsubscribe() + }() for { select { case <-m.quit: return + case <-sub.Err(): + return case event := <-events: m.handleEvent(event) } @@ -143,19 +152,19 @@ func (m *EnvelopesMonitor) handleEnvelopeEvents() { // handleEvent based on type of the event either triggers // confirmation handler or removes hash from tracker -func (m *EnvelopesMonitor) handleEvent(event whisper.EnvelopeEvent) { - handlers := map[whisper.EventType]func(whisper.EnvelopeEvent){ - whisper.EventEnvelopeSent: m.handleEventEnvelopeSent, - whisper.EventEnvelopeExpired: m.handleEventEnvelopeExpired, - whisper.EventBatchAcknowledged: m.handleAcknowledgedBatch, - whisper.EventEnvelopeReceived: m.handleEventEnvelopeReceived, +func (m *EnvelopesMonitor) handleEvent(event whispertypes.EnvelopeEvent) { + handlers := map[whispertypes.EventType]func(whispertypes.EnvelopeEvent){ + whispertypes.EventEnvelopeSent: m.handleEventEnvelopeSent, + whispertypes.EventEnvelopeExpired: m.handleEventEnvelopeExpired, + whispertypes.EventBatchAcknowledged: m.handleAcknowledgedBatch, + whispertypes.EventEnvelopeReceived: m.handleEventEnvelopeReceived, } if handler, ok := handlers[event.Event]; ok { handler(event) } } -func (m *EnvelopesMonitor) handleEventEnvelopeSent(event whisper.EnvelopeEvent) { +func (m *EnvelopesMonitor) handleEventEnvelopeSent(event whispertypes.EnvelopeEvent) { if m.mailServerConfirmation { if !m.isMailserver(event.Peer) { return @@ -172,9 +181,9 @@ func (m *EnvelopesMonitor) handleEventEnvelopeSent(event whisper.EnvelopeEvent) return } m.logger.Debug("envelope is sent", zap.String("hash", event.Hash.String()), zap.String("peer", event.Peer.String())) - if event.Batch != (common.Hash{}) { + if event.Batch != (statusproto.Hash{}) { if _, ok := m.batches[event.Batch]; !ok { - m.batches[event.Batch] = map[common.Hash]struct{}{} + m.batches[event.Batch] = map[statusproto.Hash]struct{}{} } m.batches[event.Batch][event.Hash] = struct{}{} m.logger.Debug("waiting for a confirmation", zap.String("batch", event.Batch.String())) @@ -186,7 +195,7 @@ func (m *EnvelopesMonitor) handleEventEnvelopeSent(event whisper.EnvelopeEvent) } } -func (m *EnvelopesMonitor) handleAcknowledgedBatch(event whisper.EnvelopeEvent) { +func (m *EnvelopesMonitor) handleAcknowledgedBatch(event whispertypes.EnvelopeEvent) { if m.mailServerConfirmation { if !m.isMailserver(event.Peer) { return @@ -201,11 +210,11 @@ func (m *EnvelopesMonitor) handleAcknowledgedBatch(event whisper.EnvelopeEvent) m.logger.Debug("batch is not found", zap.String("batch", event.Batch.String())) } m.logger.Debug("received a confirmation", zap.String("batch", event.Batch.String()), zap.String("peer", event.Peer.String())) - envelopeErrors, ok := event.Data.([]whisper.EnvelopeError) + envelopeErrors, ok := event.Data.([]whispertypes.EnvelopeError) if event.Data != nil && !ok { m.logger.Error("received unexpected data in the the confirmation event", zap.String("batch", event.Batch.String())) } - failedEnvelopes := map[common.Hash]struct{}{} + failedEnvelopes := map[statusproto.Hash]struct{}{} for i := range envelopeErrors { envelopeError := envelopeErrors[i] _, exist := m.envelopes[envelopeError.Hash] @@ -213,7 +222,7 @@ func (m *EnvelopesMonitor) handleAcknowledgedBatch(event whisper.EnvelopeEvent) m.logger.Warn("envelope that was posted by us is discarded", zap.String("hash", envelopeError.Hash.String()), zap.String("peer", event.Peer.String()), zap.String("error", envelopeError.Description)) var err error switch envelopeError.Code { - case whisper.EnvelopeTimeNotSynced: + case whispertypes.EnvelopeTimeNotSynced: err = errors.New("envelope wasn't delivered due to time sync issues") } m.handleEnvelopeFailure(envelopeError.Hash, err) @@ -237,7 +246,7 @@ func (m *EnvelopesMonitor) handleAcknowledgedBatch(event whisper.EnvelopeEvent) delete(m.batches, event.Batch) } -func (m *EnvelopesMonitor) handleEventEnvelopeExpired(event whisper.EnvelopeEvent) { +func (m *EnvelopesMonitor) handleEventEnvelopeExpired(event whispertypes.EnvelopeEvent) { m.mu.Lock() defer m.mu.Unlock() m.handleEnvelopeFailure(event.Hash, errors.New("envelope expired due to connectivity issues")) @@ -245,7 +254,7 @@ func (m *EnvelopesMonitor) handleEventEnvelopeExpired(event whisper.EnvelopeEven // handleEnvelopeFailure is a common code path for processing envelopes failures. not thread safe, lock // must be used on a higher level. -func (m *EnvelopesMonitor) handleEnvelopeFailure(hash common.Hash, err error) { +func (m *EnvelopesMonitor) handleEnvelopeFailure(hash statusproto.Hash, err error) { if state, ok := m.envelopes[hash]; ok { message, exist := m.messages[hash] if !exist { @@ -259,7 +268,7 @@ func (m *EnvelopesMonitor) handleEnvelopeFailure(hash common.Hash, err error) { } if attempt < m.maxAttempts { m.logger.Debug("retrying to send a message", zap.String("hash", hash.String()), zap.Int("attempt", attempt+1)) - hex, err := m.whisperAPI.Post(context.TODO(), message) + hex, err := m.whisperAPI.Post(context.TODO(), *message) if err != nil { m.logger.Error("failed to retry sending message", zap.String("hash", hash.String()), zap.Int("attempt", attempt+1), zap.Error(err)) if m.handler != nil { @@ -267,7 +276,7 @@ func (m *EnvelopesMonitor) handleEnvelopeFailure(hash common.Hash, err error) { } } - envelopeID := common.BytesToHash(hex) + envelopeID := statusproto.BytesToHash(hex) m.envelopes[envelopeID] = EnvelopePosted m.messages[envelopeID] = message m.attempts[envelopeID] = attempt + 1 @@ -281,7 +290,7 @@ func (m *EnvelopesMonitor) handleEnvelopeFailure(hash common.Hash, err error) { } } -func (m *EnvelopesMonitor) handleEventEnvelopeReceived(event whisper.EnvelopeEvent) { +func (m *EnvelopesMonitor) handleEventEnvelopeReceived(event whispertypes.EnvelopeEvent) { if m.mailServerConfirmation { if !m.isMailserver(event.Peer) { return @@ -302,7 +311,7 @@ func (m *EnvelopesMonitor) handleEventEnvelopeReceived(event whisper.EnvelopeEve // clearMessageState removes all message and envelope state. // not thread-safe, should be protected on a higher level. -func (m *EnvelopesMonitor) clearMessageState(envelopeID common.Hash) { +func (m *EnvelopesMonitor) clearMessageState(envelopeID statusproto.Hash) { delete(m.envelopes, envelopeID) delete(m.messages, envelopeID) delete(m.attempts, envelopeID) diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/filter.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/filter.go index b08dc3571..b42f686c4 100644 --- a/vendor/github.com/status-im/status-protocol-go/transport/whisper/filter.go +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/filter.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/pkg/errors" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" "go.uber.org/zap" ) @@ -26,15 +26,10 @@ var ( type whisperFilter struct { FilterID string - Topic whisper.TopicType + Topic whispertypes.TopicType SymKeyID string } -type NegotiatedSecret struct { - PublicKey *ecdsa.PublicKey - Key []byte -} - // TODO: revise fields encoding/decoding. Some are encoded using hexutil and some using encoding/hex. type Filter struct { // ChatID is the identifier of the chat @@ -49,7 +44,7 @@ type Filter struct { // It's encoded using encoding/hex. Identity string `json:"identity"` // Topic is the whisper topic - Topic whisper.TopicType `json:"topic"` + Topic whispertypes.TopicType `json:"topic"` // Discovery is whether this is a discovery topic Discovery bool `json:"discovery"` // Negotiated tells us whether is a negotiated topic @@ -63,7 +58,7 @@ func (c *Filter) IsPublic() bool { } type filtersManager struct { - whisper *whisper.Whisper + whisper whispertypes.Whisper persistence *sqlitePersistence privateKey *ecdsa.PrivateKey keys map[string][]byte // a cache of symmetric manager derived from passwords @@ -76,7 +71,7 @@ type filtersManager struct { } // newFiltersManager returns a new filtersManager. -func newFiltersManager(db *sql.DB, w *whisper.Whisper, privateKey *ecdsa.PrivateKey, logger *zap.Logger) (*filtersManager, error) { +func newFiltersManager(db *sql.DB, w whispertypes.Whisper, privateKey *ecdsa.PrivateKey, logger *zap.Logger) (*filtersManager, error) { if logger == nil { logger = zap.NewNop() } @@ -288,7 +283,7 @@ func (s *filtersManager) loadPartitioned(publicKey *ecdsa.PublicKey, listen bool } // LoadNegotiated loads a negotiated secret as a filter. -func (s *filtersManager) LoadNegotiated(secret NegotiatedSecret) (*Filter, error) { +func (s *filtersManager) LoadNegotiated(secret whispertypes.NegotiatedSecret) (*Filter, error) { s.mutex.Lock() defer s.mutex.Unlock() @@ -483,13 +478,11 @@ func (s *filtersManager) addSymmetric(chatID string) (*whisperFilter, error) { } } - f := &whisper.Filter{ - KeySym: symKey, - PoW: minPow, - AllowP2P: true, - Topics: topics, - Messages: s.whisper.NewMessageStore(), - } + f := s.whisper.CreateFilterWrapper( + nil, symKey, + minPow, + topics, + s.whisper.NewMessageStore()) id, err := s.whisper.Subscribe(f) if err != nil { @@ -499,7 +492,7 @@ func (s *filtersManager) addSymmetric(chatID string) (*whisperFilter, error) { return &whisperFilter{ FilterID: id, SymKeyID: symKeyID, - Topic: whisper.BytesToTopic(topic), + Topic: whispertypes.BytesToTopic(topic), }, nil } @@ -518,19 +511,17 @@ func (s *filtersManager) addAsymmetric(chatID string, listen bool) (*whisperFilt topic := toTopic(chatID) topics := [][]byte{topic} - f := &whisper.Filter{ - KeyAsym: s.privateKey, - PoW: pow, - AllowP2P: true, - Topics: topics, - Messages: s.whisper.NewMessageStore(), - } + f := s.whisper.CreateFilterWrapper( + s.privateKey, nil, + pow, + topics, + s.whisper.NewMessageStore()) id, err := s.whisper.Subscribe(f) if err != nil { return nil, err } - return &whisperFilter{FilterID: id, Topic: whisper.BytesToTopic(topic)}, nil + return &whisperFilter{FilterID: id, Topic: whispertypes.BytesToTopic(topic)}, nil } // GetNegotiated returns a negotiated chat given an identity @@ -542,7 +533,7 @@ func (s *filtersManager) GetNegotiated(identity *ecdsa.PublicKey) *Filter { } func toTopic(s string) []byte { - return crypto.Keccak256([]byte(s))[:whisper.TopicLength] + return crypto.Keccak256([]byte(s))[:whispertypes.TopicLength] } // ToTopic converts a string to a whisper topic. diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope.go new file mode 100644 index 000000000..fd07d625d --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope.go @@ -0,0 +1,31 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +type gethEnvelopeWrapper struct { + envelope *whisper.Envelope +} + +// NewGethEnvelopeWrapper returns an object that wraps Geth's Envelope in a whispertypes interface +func NewGethEnvelopeWrapper(e *whisper.Envelope) whispertypes.Envelope { + return &gethEnvelopeWrapper{ + envelope: e, + } +} + +// GetGethEnvelopeFrom retrieves the underlying whisper Envelope struct from a wrapped Envelope interface +func GetGethEnvelopeFrom(f whispertypes.Envelope) *whisper.Envelope { + return f.(*gethEnvelopeWrapper).envelope +} + +func (w *gethEnvelopeWrapper) Hash() statusproto.Hash { + return statusproto.Hash(w.envelope.Hash()) +} + +func (w *gethEnvelopeWrapper) Bloom() []byte { + return w.envelope.Bloom() +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope_error.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope_error.go new file mode 100644 index 000000000..61f81d98b --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope_error.go @@ -0,0 +1,30 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +// NewGethEnvelopeErrorWrapper returns a whispertypes.EnvelopeError object that mimics Geth's EnvelopeError +func NewGethEnvelopeErrorWrapper(envelopeError *whisper.EnvelopeError) *whispertypes.EnvelopeError { + if envelopeError == nil { + panic("envelopeError should not be nil") + } + + return &whispertypes.EnvelopeError{ + Hash: statusproto.Hash(envelopeError.Hash), + Code: mapGethErrorCode(envelopeError.Code), + Description: envelopeError.Description, + } +} + +func mapGethErrorCode(code uint) uint { + switch code { + case whisper.EnvelopeTimeNotSynced: + return whispertypes.EnvelopeTimeNotSynced + case whisper.EnvelopeOtherError: + return whispertypes.EnvelopeOtherError + } + return whispertypes.EnvelopeOtherError +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope_event.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope_event.go new file mode 100644 index 000000000..6e6de9c1c --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/envelope_event.go @@ -0,0 +1,34 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +// NewGethEnvelopeEventWrapper returns a whispertypes.EnvelopeEvent object that mimics Geth's EnvelopeEvent +func NewGethEnvelopeEventWrapper(envelopeEvent *whisper.EnvelopeEvent) *whispertypes.EnvelopeEvent { + if envelopeEvent == nil { + panic("envelopeEvent should not be nil") + } + + wrappedData := envelopeEvent.Data + switch data := envelopeEvent.Data.(type) { + case []whisper.EnvelopeError: + wrappedData := make([]whispertypes.EnvelopeError, len(data)) + for index, envError := range data { + wrappedData[index] = *NewGethEnvelopeErrorWrapper(&envError) + } + case *whisper.MailServerResponse: + wrappedData = NewGethMailServerResponseWrapper(data) + case whisper.SyncEventResponse: + wrappedData = NewGethSyncEventResponseWrapper(data) + } + return &whispertypes.EnvelopeEvent{ + Event: whispertypes.EventType(envelopeEvent.Event), + Hash: statusproto.Hash(envelopeEvent.Hash), + Batch: statusproto.Hash(envelopeEvent.Batch), + Peer: whispertypes.EnodeID(envelopeEvent.Peer), + Data: wrappedData, + } +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/filter.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/filter.go new file mode 100644 index 000000000..413c1fdb4 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/filter.go @@ -0,0 +1,38 @@ +package gethbridge + +import ( + "crypto/ecdsa" + + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +type gethFilterWrapper struct { + filter *whisper.Filter +} + +// NewGethFilterWrapper returns an object that wraps Geth's Filter in a whispertypes interface +func NewGethFilterWrapper(f *whisper.Filter) whispertypes.Filter { + if f.Messages == nil { + panic("Messages should not be nil") + } + + return &gethFilterWrapper{ + filter: f, + } +} + +// GetGethFilterFrom retrieves the underlying whisper Filter struct from a wrapped Filter interface +func GetGethFilterFrom(f whispertypes.Filter) *whisper.Filter { + return f.(*gethFilterWrapper).filter +} + +// KeyAsym returns the private Key of recipient +func (w *gethFilterWrapper) KeyAsym() *ecdsa.PrivateKey { + return w.filter.KeyAsym +} + +// KeySym returns the key associated with the Topic +func (w *gethFilterWrapper) KeySym() []byte { + return w.filter.KeySym +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/mailserver_response.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/mailserver_response.go new file mode 100644 index 000000000..1d9acd0df --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/mailserver_response.go @@ -0,0 +1,20 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +// NewGethMailServerResponseWrapper returns a whispertypes.MailServerResponse object that mimics Geth's MailServerResponse +func NewGethMailServerResponseWrapper(mailServerResponse *whisper.MailServerResponse) *whispertypes.MailServerResponse { + if mailServerResponse == nil { + panic("mailServerResponse should not be nil") + } + + return &whispertypes.MailServerResponse{ + LastEnvelopeHash: statusproto.Hash(mailServerResponse.LastEnvelopeHash), + Cursor: mailServerResponse.Cursor, + Error: mailServerResponse.Error, + } +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/message_store.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/message_store.go new file mode 100644 index 000000000..e63ec7ea3 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/message_store.go @@ -0,0 +1,43 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +type gethMessageStoreWrapper struct { + messageStore whisper.MessageStore +} + +// NewGethMessageStoreWrapper returns an object that wraps Geth's MessageStore in a whispertypes interface +func NewGethMessageStoreWrapper(messageStore whisper.MessageStore) whispertypes.MessageStore { + if messageStore == nil { + panic("messageStore cannot be nil") + } + + return &gethMessageStoreWrapper{ + messageStore: messageStore, + } +} + +// GetGethMessageStoreFrom retrieves the underlying whisper MessageStore interface from a wrapped MessageStore interface +func GetGethMessageStoreFrom(m whispertypes.MessageStore) whisper.MessageStore { + return m.(*gethMessageStoreWrapper).messageStore +} + +func (w *gethMessageStoreWrapper) Add(m whispertypes.ReceivedMessage) error { + return w.messageStore.Add(GetGethReceivedMessageFrom(m)) +} + +func (w *gethMessageStoreWrapper) Pop() ([]whispertypes.ReceivedMessage, error) { + msgs, err := w.messageStore.Pop() + if err != nil { + return nil, err + } + + wrappedMsgs := make([]whispertypes.ReceivedMessage, len(msgs)) + for index, m := range msgs { + wrappedMsgs[index] = NewGethReceivedMessageWrapper(m) + } + return wrappedMsgs, err +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/public_whisper_api.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/public_whisper_api.go new file mode 100644 index 000000000..25090f926 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/public_whisper_api.go @@ -0,0 +1,103 @@ +package gethbridge + +import ( + "context" + + "github.com/ethereum/go-ethereum/common/hexutil" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +type gethPublicWhisperAPIWrapper struct { + publicWhisperAPI *whisper.PublicWhisperAPI +} + +// NewGethPublicWhisperAPIWrapper returns an object that wraps Geth's PublicWhisperAPI in a whispertypes interface +func NewGethPublicWhisperAPIWrapper(publicWhisperAPI *whisper.PublicWhisperAPI) whispertypes.PublicWhisperAPI { + if publicWhisperAPI == nil { + panic("publicWhisperAPI cannot be nil") + } + + return &gethPublicWhisperAPIWrapper{ + publicWhisperAPI: publicWhisperAPI, + } +} + +// AddPrivateKey imports the given private key. +func (w *gethPublicWhisperAPIWrapper) AddPrivateKey(ctx context.Context, privateKey statusproto.HexBytes) (string, error) { + return w.publicWhisperAPI.AddPrivateKey(ctx, hexutil.Bytes(privateKey)) +} + +// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID. +func (w *gethPublicWhisperAPIWrapper) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) { + return w.publicWhisperAPI.GenerateSymKeyFromPassword(ctx, passwd) +} + +// DeleteKeyPair removes the key with the given key if it exists. +func (w *gethPublicWhisperAPIWrapper) DeleteKeyPair(ctx context.Context, key string) (bool, error) { + return w.publicWhisperAPI.DeleteKeyPair(ctx, key) +} + +// NewMessageFilter creates a new filter that can be used to poll for +// (new) messages that satisfy the given criteria. +func (w *gethPublicWhisperAPIWrapper) NewMessageFilter(req whispertypes.Criteria) (string, error) { + topics := make([]whisper.TopicType, len(req.Topics)) + for index, tt := range req.Topics { + topics[index] = whisper.TopicType(tt) + } + + criteria := whisper.Criteria{ + SymKeyID: req.SymKeyID, + PrivateKeyID: req.PrivateKeyID, + Sig: req.Sig, + MinPow: req.MinPow, + Topics: topics, + AllowP2P: req.AllowP2P, + } + return w.publicWhisperAPI.NewMessageFilter(criteria) +} + +// GetFilterMessages returns the messages that match the filter criteria and +// are received between the last poll and now. +func (w *gethPublicWhisperAPIWrapper) GetFilterMessages(id string) ([]*whispertypes.Message, error) { + msgs, err := w.publicWhisperAPI.GetFilterMessages(id) + if err != nil { + return nil, err + } + + wrappedMsgs := make([]*whispertypes.Message, len(msgs)) + for index, msg := range msgs { + wrappedMsgs[index] = &whispertypes.Message{ + Sig: msg.Sig, + TTL: msg.TTL, + Timestamp: msg.Timestamp, + Topic: whispertypes.TopicType(msg.Topic), + Payload: msg.Payload, + Padding: msg.Padding, + PoW: msg.PoW, + Hash: msg.Hash, + Dst: msg.Dst, + P2P: msg.P2P, + } + } + return wrappedMsgs, nil +} + +// Post posts a message on the Whisper network. +// returns the hash of the message in case of success. +func (w *gethPublicWhisperAPIWrapper) Post(ctx context.Context, req whispertypes.NewMessage) ([]byte, error) { + msg := whisper.NewMessage{ + SymKeyID: req.SymKeyID, + PublicKey: req.PublicKey, + Sig: req.Sig, + TTL: req.TTL, + Topic: whisper.TopicType(req.Topic), + Payload: req.Payload, + Padding: req.Padding, + PowTime: req.PowTime, + PowTarget: req.PowTarget, + TargetPeer: req.TargetPeer, + } + return w.publicWhisperAPI.Post(ctx, msg) +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/received_message.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/received_message.go new file mode 100644 index 000000000..28a6454b8 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/received_message.go @@ -0,0 +1,26 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +type gethReceivedMessageWrapper struct { + receivedMessage *whisper.ReceivedMessage +} + +// NewGethReceivedMessageWrapper returns an object that wraps Geth's ReceivedMessage in a whispertypes interface +func NewGethReceivedMessageWrapper(receivedMessage *whisper.ReceivedMessage) whispertypes.ReceivedMessage { + if receivedMessage == nil { + panic("receivedMessage cannot be nil") + } + + return &gethReceivedMessageWrapper{ + receivedMessage: receivedMessage, + } +} + +// GetGethReceivedMessageFrom retrieves the underlying whisper ReceivedMessage struct from a wrapped ReceivedMessage interface +func GetGethReceivedMessageFrom(m whispertypes.ReceivedMessage) *whisper.ReceivedMessage { + return m.(*gethReceivedMessageWrapper).receivedMessage +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/subscription.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/subscription.go new file mode 100644 index 000000000..cb8332027 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/subscription.go @@ -0,0 +1,29 @@ +package gethbridge + +import ( + "github.com/ethereum/go-ethereum/event" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" +) + +type gethSubscriptionWrapper struct { + subscription event.Subscription +} + +// NewGethSubscriptionWrapper returns an object that wraps Geth's Subscription in a whispertypes interface +func NewGethSubscriptionWrapper(subscription event.Subscription) whispertypes.Subscription { + if subscription == nil { + panic("subscription cannot be nil") + } + + return &gethSubscriptionWrapper{ + subscription: subscription, + } +} + +func (w *gethSubscriptionWrapper) Err() <-chan error { + return w.subscription.Err() +} + +func (w *gethSubscriptionWrapper) Unsubscribe() { + w.subscription.Unsubscribe() +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/syncevent_response.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/syncevent_response.go new file mode 100644 index 000000000..c35c4c917 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/syncevent_response.go @@ -0,0 +1,14 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +// NewGethSyncEventResponseWrapper returns a whispertypes.SyncEventResponse object that mimics Geth's SyncEventResponse +func NewGethSyncEventResponseWrapper(syncEventResponse whisper.SyncEventResponse) whispertypes.SyncEventResponse { + return whispertypes.SyncEventResponse{ + Cursor: syncEventResponse.Cursor, + Error: syncEventResponse.Error, + } +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/syncmailrequest.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/syncmailrequest.go new file mode 100644 index 000000000..0df4b1693 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/syncmailrequest.go @@ -0,0 +1,17 @@ +package gethbridge + +import ( + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +// GetGethSyncMailRequestFrom converts a whisper SyncMailRequest struct from a SyncMailRequest struct +func GetGethSyncMailRequestFrom(r *whispertypes.SyncMailRequest) *whisper.SyncMailRequest { + return &whisper.SyncMailRequest{ + Lower: r.Lower, + Upper: r.Upper, + Bloom: r.Bloom, + Limit: r.Limit, + Cursor: r.Cursor, + } +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/whisper.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/whisper.go new file mode 100644 index 000000000..89520311e --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/gethbridge/whisper.go @@ -0,0 +1,150 @@ +package gethbridge + +import ( + "crypto/ecdsa" + "time" + + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + whisper "github.com/status-im/whisper/whisperv6" +) + +type gethWhisperWrapper struct { + whisper *whisper.Whisper +} + +// NewGethWhisperWrapper returns an object that wraps Geth's Whisper in a whispertypes interface +func NewGethWhisperWrapper(w *whisper.Whisper) whispertypes.Whisper { + if w == nil { + panic("w cannot be nil") + } + + return &gethWhisperWrapper{ + whisper: w, + } +} + +// GetGethWhisperFrom retrieves the underlying whisper Whisper struct from a wrapped Whisper interface +func GetGethWhisperFrom(m whispertypes.Whisper) *whisper.Whisper { + return m.(*gethWhisperWrapper).whisper +} + +func (w *gethWhisperWrapper) PublicWhisperAPI() whispertypes.PublicWhisperAPI { + return NewGethPublicWhisperAPIWrapper(whisper.NewPublicWhisperAPI(w.whisper)) +} + +func (w *gethWhisperWrapper) NewMessageStore() whispertypes.MessageStore { + return NewGethMessageStoreWrapper(w.whisper.NewMessageStore()) +} + +// MinPow returns the PoW value required by this node. +func (w *gethWhisperWrapper) MinPow() float64 { + return w.whisper.MinPow() +} + +// BloomFilter returns the aggregated bloom filter for all the topics of interest. +// The nodes are required to send only messages that match the advertised bloom filter. +// If a message does not match the bloom, it will tantamount to spam, and the peer will +// be disconnected. +func (w *gethWhisperWrapper) BloomFilter() []byte { + return w.whisper.BloomFilter() +} + +// GetCurrentTime returns current time. +func (w *gethWhisperWrapper) GetCurrentTime() time.Time { + return w.whisper.GetCurrentTime() +} + +// SetTimeSource assigns a particular source of time to a whisper object. +func (w *gethWhisperWrapper) SetTimeSource(timesource func() time.Time) { + w.whisper.SetTimeSource(timesource) +} + +func (w *gethWhisperWrapper) SubscribeEnvelopeEvents(eventsProxy chan<- whispertypes.EnvelopeEvent) whispertypes.Subscription { + events := make(chan whisper.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper + go func() { + for e := range events { + eventsProxy <- *NewGethEnvelopeEventWrapper(&e) + } + }() + + return NewGethSubscriptionWrapper(w.whisper.SubscribeEnvelopeEvents(events)) +} + +// SelectedKeyPairID returns the id of currently selected key pair. +// It helps distinguish between different users w/o exposing the user identity itself. +func (w *gethWhisperWrapper) SelectedKeyPairID() string { + return w.whisper.SelectedKeyPairID() +} + +func (w *gethWhisperWrapper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error) { + return w.whisper.GetPrivateKey(id) +} + +// AddKeyPair imports a asymmetric private key and returns a deterministic identifier. +func (w *gethWhisperWrapper) AddKeyPair(key *ecdsa.PrivateKey) (string, error) { + return w.whisper.AddKeyPair(key) +} + +// DeleteKeyPair deletes the specified key if it exists. +func (w *gethWhisperWrapper) DeleteKeyPair(key string) bool { + return w.whisper.DeleteKeyPair(key) +} + +// SelectKeyPair adds cryptographic identity, and makes sure +// that it is the only private key known to the node. +func (w *gethWhisperWrapper) SelectKeyPair(key *ecdsa.PrivateKey) error { + return w.whisper.SelectKeyPair(key) +} + +func (w *gethWhisperWrapper) AddSymKeyDirect(key []byte) (string, error) { + return w.whisper.AddSymKeyDirect(key) +} + +func (w *gethWhisperWrapper) AddSymKeyFromPassword(password string) (string, error) { + return w.whisper.AddSymKeyFromPassword(password) +} + +func (w *gethWhisperWrapper) DeleteSymKey(id string) bool { + return w.whisper.DeleteSymKey(id) +} + +func (w *gethWhisperWrapper) GetSymKey(id string) ([]byte, error) { + return w.whisper.GetSymKey(id) +} + +func (w *gethWhisperWrapper) Subscribe(f whispertypes.Filter) (string, error) { + return w.whisper.Subscribe(GetGethFilterFrom(f)) +} + +func (w *gethWhisperWrapper) GetFilter(id string) whispertypes.Filter { + return NewGethFilterWrapper(w.whisper.GetFilter(id)) +} + +func (w *gethWhisperWrapper) Unsubscribe(id string) error { + return w.whisper.Unsubscribe(id) +} + +func (w *gethWhisperWrapper) CreateFilterWrapper(keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, topics [][]byte, messages whispertypes.MessageStore) whispertypes.Filter { + return NewGethFilterWrapper(&whisper.Filter{ + KeyAsym: keyAsym, + KeySym: keySym, + PoW: pow, + AllowP2P: true, + Topics: topics, + Messages: GetGethMessageStoreFrom(messages), + }) +} + +// RequestHistoricMessages sends a message with p2pRequestCode to a specific peer, +// which is known to implement MailServer interface, and is supposed to process this +// request and respond with a number of peer-to-peer messages (possibly expired), +// which are not supposed to be forwarded any further. +// The whisper protocol is agnostic of the format and contents of envelope. +func (w *gethWhisperWrapper) RequestHistoricMessagesWithTimeout(peerID []byte, envelope whispertypes.Envelope, timeout time.Duration) error { + return w.whisper.RequestHistoricMessagesWithTimeout(peerID, GetGethEnvelopeFrom(envelope), timeout) +} + +// SyncMessages can be sent between two Mail Servers and syncs envelopes between them. +func (w *gethWhisperWrapper) SyncMessages(peerID []byte, req whispertypes.SyncMailRequest) error { + return w.whisper.SyncMessages(peerID, *GetGethSyncMailRequestFrom(&req)) +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/envelopes.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/envelopes.go new file mode 100644 index 000000000..ed503aa3f --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/envelopes.go @@ -0,0 +1,81 @@ +package whispertypes + +import statusproto "github.com/status-im/status-protocol-go/types" + +// Envelope represents a clear-text data packet to transmit through the Whisper +// network. Its contents may or may not be encrypted and signed. +type Envelope interface { + Hash() statusproto.Hash // Cached hash of the envelope to avoid rehashing every time. + Bloom() []byte +} + +// EventType used to define known envelope events. +type EventType string + +// NOTE: This list of event names is extracted from Geth. It must be kept in sync, or otherwise a mapping layer needs to be created +const ( + // EventEnvelopeSent fires when envelope was sent to a peer. + EventEnvelopeSent EventType = "envelope.sent" + // EventEnvelopeExpired fires when envelop expired + EventEnvelopeExpired EventType = "envelope.expired" + // EventEnvelopeReceived is sent once envelope was received from a peer. + // EventEnvelopeReceived must be sent to the feed even if envelope was previously in the cache. + // And event, ideally, should contain information about peer that sent envelope to us. + EventEnvelopeReceived EventType = "envelope.received" + // EventBatchAcknowledged is sent when batch of envelopes was acknowleged by a peer. + EventBatchAcknowledged EventType = "batch.acknowleged" + // EventEnvelopeAvailable fires when envelop is available for filters + EventEnvelopeAvailable EventType = "envelope.available" + // EventMailServerRequestSent fires when such request is sent. + EventMailServerRequestSent EventType = "mailserver.request.sent" + // EventMailServerRequestCompleted fires after mailserver sends all the requested messages + EventMailServerRequestCompleted EventType = "mailserver.request.completed" + // EventMailServerRequestExpired fires after mailserver the request TTL ends. + // This event is independent and concurrent to EventMailServerRequestCompleted. + // Request should be considered as expired only if expiry event was received first. + EventMailServerRequestExpired EventType = "mailserver.request.expired" + // EventMailServerEnvelopeArchived fires after an envelope has been archived + EventMailServerEnvelopeArchived EventType = "mailserver.envelope.archived" + // EventMailServerSyncFinished fires when the sync of messages is finished. + EventMailServerSyncFinished EventType = "mailserver.sync.finished" +) + +const ( + EnvelopeTimeNotSynced uint = 1000 + EnvelopeOtherError +) + +// EnvelopeEvent used for envelopes events. +type EnvelopeEvent struct { + Event EventType + Hash statusproto.Hash + Batch statusproto.Hash + Peer EnodeID + Data interface{} +} + +// EnvelopeError code and optional description of the error. +type EnvelopeError struct { + Hash statusproto.Hash + Code uint + Description string +} + +// Subscription represents a stream of events. The carrier of the events is typically a +// channel, but isn't part of the interface. +// +// Subscriptions can fail while established. Failures are reported through an error +// channel. It receives a value if there is an issue with the subscription (e.g. the +// network connection delivering the events has been closed). Only one value will ever be +// sent. +// +// The error channel is closed when the subscription ends successfully (i.e. when the +// source of events is closed). It is also closed when Unsubscribe is called. +// +// The Unsubscribe method cancels the sending of events. You must call Unsubscribe in all +// cases to ensure that resources related to the subscription are released. It can be +// called any number of times. +type Subscription interface { + Err() <-chan error // returns the error channel + Unsubscribe() // cancels sending of events, closing the error channel +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/filter.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/filter.go new file mode 100644 index 000000000..2f3cafe53 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/filter.go @@ -0,0 +1,17 @@ +package whispertypes + +import ( + "crypto/ecdsa" +) + +// Filter represents a Whisper message filter +type Filter interface { + KeyAsym() *ecdsa.PrivateKey // Private Key of recipient + KeySym() []byte // Key associated with the Topic +} + +// MessageStore defines the interface for a temporary message store. +type MessageStore interface { + Add(ReceivedMessage) error + Pop() ([]ReceivedMessage, error) +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/mailserver.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/mailserver.go new file mode 100644 index 000000000..baea6b3d4 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/mailserver.go @@ -0,0 +1,32 @@ +package whispertypes + +import statusproto "github.com/status-im/status-protocol-go/types" + +// MailServerResponse is the response payload sent by the mailserver +type MailServerResponse struct { + LastEnvelopeHash statusproto.Hash + Cursor []byte + Error error +} + +// SyncMailRequest contains details which envelopes should be synced +// between Mail Servers. +type SyncMailRequest struct { + // Lower is a lower bound of time range for which messages are requested. + Lower uint32 + // Upper is a lower bound of time range for which messages are requested. + Upper uint32 + // Bloom is a bloom filter to filter envelopes. + Bloom []byte + // Limit is the max number of envelopes to return. + Limit uint32 + // Cursor is used for pagination of the results. + Cursor []byte +} + +// SyncEventResponse is a response from the Mail Server +// form which the peer received envelopes. +type SyncEventResponse struct { + Cursor []byte + Error string +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/negotiated_secret.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/negotiated_secret.go new file mode 100644 index 000000000..d852e4bb5 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/negotiated_secret.go @@ -0,0 +1,10 @@ +package whispertypes + +import ( + "crypto/ecdsa" +) + +type NegotiatedSecret struct { + PublicKey *ecdsa.PublicKey + Key []byte +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/node.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/node.go new file mode 100644 index 000000000..d3f960d16 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/node.go @@ -0,0 +1,11 @@ +package whispertypes + +import "fmt" + +// EnodeID is a unique identifier for each node. +type EnodeID [32]byte + +// ID prints as a long hexadecimal number. +func (n EnodeID) String() string { + return fmt.Sprintf("%x", n[:]) +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/received_message.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/received_message.go new file mode 100644 index 000000000..af1de341e --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/received_message.go @@ -0,0 +1,6 @@ +package whispertypes + +// ReceivedMessage represents a data packet to be received through the +// Whisper protocol and successfully decrypted. +type ReceivedMessage interface { +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/rpc.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/rpc.go new file mode 100644 index 000000000..9b1fc74f7 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/rpc.go @@ -0,0 +1,67 @@ +package whispertypes + +import ( + "context" + + statusproto "github.com/status-im/status-protocol-go/types" +) + +// NewMessage represents a new whisper message that is posted through the RPC. +type NewMessage struct { + SymKeyID string `json:"symKeyID"` + PublicKey []byte `json:"pubKey"` + Sig string `json:"sig"` + TTL uint32 `json:"ttl"` + Topic TopicType `json:"topic"` + Payload []byte `json:"payload"` + Padding []byte `json:"padding"` + PowTime uint32 `json:"powTime"` + PowTarget float64 `json:"powTarget"` + TargetPeer string `json:"targetPeer"` +} + +// Message is the RPC representation of a whisper message. +type Message struct { + Sig []byte `json:"sig,omitempty"` + TTL uint32 `json:"ttl"` + Timestamp uint32 `json:"timestamp"` + Topic TopicType `json:"topic"` + Payload []byte `json:"payload"` + Padding []byte `json:"padding"` + PoW float64 `json:"pow"` + Hash []byte `json:"hash"` + Dst []byte `json:"recipientPublicKey,omitempty"` + P2P bool `json:"bool,omitempty"` +} + +// Criteria holds various filter options for inbound messages. +type Criteria struct { + SymKeyID string `json:"symKeyID"` + PrivateKeyID string `json:"privateKeyID"` + Sig []byte `json:"sig"` + MinPow float64 `json:"minPow"` + Topics []TopicType `json:"topics"` + AllowP2P bool `json:"allowP2P"` +} + +// PublicWhisperAPI provides the whisper RPC service that can be +// use publicly without security implications. +type PublicWhisperAPI interface { + // AddPrivateKey imports the given private key. + AddPrivateKey(ctx context.Context, privateKey statusproto.HexBytes) (string, error) + // GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID. + GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) + // DeleteKeyPair removes the key with the given key if it exists. + DeleteKeyPair(ctx context.Context, key string) (bool, error) + + // Post posts a message on the Whisper network. + // returns the hash of the message in case of success. + Post(ctx context.Context, req NewMessage) ([]byte, error) + + // NewMessageFilter creates a new filter that can be used to poll for + // (new) messages that satisfy the given criteria. + NewMessageFilter(req Criteria) (string, error) + // GetFilterMessages returns the messages that match the filter criteria and + // are received between the last poll and now. + GetFilterMessages(id string) ([]*Message, error) +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/topic.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/topic.go new file mode 100644 index 000000000..b6d3c7eab --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/topic.go @@ -0,0 +1,88 @@ +package whispertypes + +import ( + "github.com/ethereum/go-ethereum/common/hexutil" + statusproto "github.com/status-im/status-protocol-go/types" +) + +const ( + // TopicLength is the expected length of the topic, in bytes + TopicLength = 4 + BloomFilterSize = 64 // in bytes +) + +// TopicType represents a cryptographically secure, probabilistic partial +// classifications of a message, determined as the first (left) 4 bytes of the +// SHA3 hash of some arbitrary data given by the original author of the message. +type TopicType [TopicLength]byte + +// BytesToTopic converts from the byte array representation of a topic +// into the TopicType type. +func BytesToTopic(b []byte) (t TopicType) { + sz := TopicLength + if x := len(b); x < TopicLength { + sz = x + } + for i := 0; i < sz; i++ { + t[i] = b[i] + } + return t +} + +// String converts a topic byte array to a string representation. +func (t *TopicType) String() string { + return statusproto.EncodeHex(t[:]) +} + +// MarshalText returns the hex representation of t. +func (t TopicType) MarshalText() ([]byte, error) { + return statusproto.HexBytes(t[:]).MarshalText() +} + +// UnmarshalText parses a hex representation to a topic. +func (t *TopicType) UnmarshalText(input []byte) error { + return hexutil.UnmarshalFixedText("Topic", input, t[:]) +} + +// TopicToBloom converts the topic (4 bytes) to the bloom filter (64 bytes) +func TopicToBloom(topic TopicType) []byte { + b := make([]byte, BloomFilterSize) + var index [3]int + for j := 0; j < 3; j++ { + index[j] = int(topic[j]) + if (topic[3] & (1 << uint(j))) != 0 { + index[j] += 256 + } + } + + for j := 0; j < 3; j++ { + byteIndex := index[j] / 8 + bitIndex := index[j] % 8 + b[byteIndex] = (1 << uint(bitIndex)) + } + return b +} + +func BloomFilterMatch(filter, sample []byte) bool { + if filter == nil { + return true + } + + for i := 0; i < BloomFilterSize; i++ { + f := filter[i] + s := sample[i] + if (f | s) != f { + return false + } + } + + return true +} + +func MakeFullNodeBloom() []byte { + bloom := make([]byte, BloomFilterSize) + for i := 0; i < BloomFilterSize; i++ { + bloom[i] = 0xFF + } + return bloom +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/whisper.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/whisper.go new file mode 100644 index 000000000..f6b9bf527 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/types/whisper.go @@ -0,0 +1,61 @@ +package whispertypes + +import ( + "crypto/ecdsa" + "time" +) + +// Whisper represents a dark communication interface through the Ethereum +// network, using its very own P2P communication layer. +type Whisper interface { + PublicWhisperAPI() PublicWhisperAPI + NewMessageStore() MessageStore + + // MinPow returns the PoW value required by this node. + MinPow() float64 + // BloomFilter returns the aggregated bloom filter for all the topics of interest. + // The nodes are required to send only messages that match the advertised bloom filter. + // If a message does not match the bloom, it will tantamount to spam, and the peer will + // be disconnected. + BloomFilter() []byte + // SetTimeSource assigns a particular source of time to a whisper object. + SetTimeSource(timesource func() time.Time) + // GetCurrentTime returns current time. + GetCurrentTime() time.Time + + // SelectedKeyPairID returns the id of currently selected key pair. + // It helps distinguish between different users w/o exposing the user identity itself. + SelectedKeyPairID() string + // GetPrivateKey retrieves the private key of the specified identity. + GetPrivateKey(id string) (*ecdsa.PrivateKey, error) + + SubscribeEnvelopeEvents(events chan<- EnvelopeEvent) Subscription + + // AddKeyPair imports a asymmetric private key and returns a deterministic identifier. + AddKeyPair(key *ecdsa.PrivateKey) (string, error) + // DeleteKeyPair deletes the specified key if it exists. + DeleteKeyPair(key string) bool + // SelectKeyPair adds cryptographic identity, and makes sure + // that it is the only private key known to the node. + SelectKeyPair(key *ecdsa.PrivateKey) error + AddSymKeyDirect(key []byte) (string, error) + AddSymKeyFromPassword(password string) (string, error) + DeleteSymKey(id string) bool + GetSymKey(id string) ([]byte, error) + + Subscribe(f Filter) (string, error) + GetFilter(id string) Filter + Unsubscribe(id string) error + + CreateFilterWrapper(keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, topics [][]byte, messages MessageStore) Filter + + // RequestHistoricMessages sends a message with p2pRequestCode to a specific peer, + // which is known to implement MailServer interface, and is supposed to process this + // request and respond with a number of peer-to-peer messages (possibly expired), + // which are not supposed to be forwarded any further. + // The whisper protocol is agnostic of the format and contents of envelope. + // A timeout of 0 never expires. + RequestHistoricMessagesWithTimeout(peerID []byte, envelope Envelope, timeout time.Duration) error + // SyncMessages can be sent between two Mail Servers and syncs envelopes between them. + SyncMessages(peerID []byte, req SyncMailRequest) error +} diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper.go index 012332176..3af2a6124 100644 --- a/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper.go +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper.go @@ -1,11 +1,11 @@ package whisper import ( - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" ) type RequestOptions struct { - Topics []whisper.TopicType + Topics []whispertypes.TopicType Password string Limit int From int64 // in seconds @@ -16,8 +16,8 @@ const ( defaultPowTime = 1 ) -func DefaultWhisperMessage() whisper.NewMessage { - msg := whisper.NewMessage{} +func DefaultWhisperMessage() whispertypes.NewMessage { + msg := whispertypes.NewMessage{} msg.TTL = 10 msg.PowTarget = 0.002 diff --git a/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper_service.go b/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper_service.go index c425d0d42..7214c6764 100644 --- a/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper_service.go +++ b/vendor/github.com/status-im/status-protocol-go/transport/whisper/whisper_service.go @@ -7,11 +7,12 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/pkg/errors" - whisper "github.com/status-im/whisper/whisperv6" "go.uber.org/zap" + + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" ) var ( @@ -20,7 +21,7 @@ var ( ) type whisperServiceKeysManager struct { - shh *whisper.Whisper + shh whispertypes.Whisper // Identity of the current user. privateKey *ecdsa.PrivateKey @@ -67,8 +68,8 @@ func SetGenericDiscoveryTopicSupport(val bool) Option { // WhisperServiceTransport is a transport based on Whisper service. type WhisperServiceTransport struct { - shh *whisper.Whisper - shhAPI *whisper.PublicWhisperAPI // only PublicWhisperAPI implements logic to send messages + shh whispertypes.Whisper + shhAPI whispertypes.PublicWhisperAPI // only PublicWhisperAPI implements logic to send messages keysManager *whisperServiceKeysManager filters *filtersManager logger *zap.Logger @@ -79,9 +80,9 @@ type WhisperServiceTransport struct { genericDiscoveryTopicEnabled bool } -// NewWhisperService returns a new WhisperServiceTransport. +// NewWhisperServiceTransport returns a new WhisperServiceTransport. func NewWhisperServiceTransport( - shh *whisper.Whisper, + shh whispertypes.Whisper, privateKey *ecdsa.PrivateKey, db *sql.DB, mailservers []string, @@ -96,13 +97,17 @@ func NewWhisperServiceTransport( var envelopesMonitor *EnvelopesMonitor if envelopesMonitorConfig != nil { - envelopesMonitor = NewEnvelopesMonitor(shh, envelopesMonitorConfig) + envelopesMonitor = NewEnvelopesMonitor(shh, *envelopesMonitorConfig) envelopesMonitor.Start() } + var shhAPI whispertypes.PublicWhisperAPI + if shh != nil { + shhAPI = shh.PublicWhisperAPI() + } t := &WhisperServiceTransport{ shh: shh, - shhAPI: whisper.NewPublicWhisperAPI(shh), + shhAPI: shhAPI, envelopesMonitor: envelopesMonitor, keysManager: &whisperServiceKeysManager{ shh: shh, @@ -145,7 +150,7 @@ func (a *WhisperServiceTransport) Reset() error { return a.filters.Reset() } -func (a *WhisperServiceTransport) ProcessNegotiatedSecret(secret NegotiatedSecret) (*Filter, error) { +func (a *WhisperServiceTransport) ProcessNegotiatedSecret(secret whispertypes.NegotiatedSecret) (*Filter, error) { filter, err := a.filters.LoadNegotiated(secret) if err != nil { return nil, err @@ -181,7 +186,7 @@ func (a *WhisperServiceTransport) LeavePrivate(publicKey *ecdsa.PublicKey) error } type Message struct { - Message *whisper.ReceivedMessage // TODO: should it be whisper.Message? + Message *whispertypes.Message Public bool } @@ -189,12 +194,12 @@ func (a *WhisperServiceTransport) RetrieveAllMessages() ([]Message, error) { var messages []Message for _, filter := range a.filters.Filters() { - f := a.shh.GetFilter(filter.FilterID) - if f == nil { - return nil, errors.New("failed to return a filter") + filterMsgs, err := a.shhAPI.GetFilterMessages(filter.FilterID) + if err != nil { + return nil, err } - for _, m := range f.Retrieve() { + for _, m := range filterMsgs { messages = append(messages, Message{ Message: m, Public: filter.IsPublic(), @@ -205,36 +210,31 @@ func (a *WhisperServiceTransport) RetrieveAllMessages() ([]Message, error) { return messages, nil } -func (a *WhisperServiceTransport) RetrievePublicMessages(chatID string) ([]*whisper.ReceivedMessage, error) { +func (a *WhisperServiceTransport) RetrievePublicMessages(chatID string) ([]*whispertypes.Message, error) { filter, err := a.filters.LoadPublic(chatID) if err != nil { return nil, err } - f := a.shh.GetFilter(filter.FilterID) - if f == nil { - return nil, errors.New("failed to return a filter") - } - - return f.Retrieve(), nil + return a.shhAPI.GetFilterMessages(filter.FilterID) } -func (a *WhisperServiceTransport) RetrievePrivateMessages(publicKey *ecdsa.PublicKey) ([]*whisper.ReceivedMessage, error) { +func (a *WhisperServiceTransport) RetrievePrivateMessages(publicKey *ecdsa.PublicKey) ([]*whispertypes.Message, error) { chats := a.filters.FiltersByPublicKey(publicKey) discoveryChats, err := a.filters.Init(nil, nil, true) if err != nil { return nil, err } - var result []*whisper.ReceivedMessage + var result []*whispertypes.Message for _, chat := range append(chats, discoveryChats...) { - f := a.shh.GetFilter(chat.FilterID) - if f == nil { - return nil, errors.New("failed to return a filter") + filterMsgs, err := a.shhAPI.GetFilterMessages(chat.FilterID) + if err != nil { + return nil, err } - result = append(result, f.Retrieve()...) + result = append(result, filterMsgs...) } return result, nil @@ -242,35 +242,19 @@ func (a *WhisperServiceTransport) RetrievePrivateMessages(publicKey *ecdsa.Publi // DEPRECATED // Use RetrieveAllMessages instead. -func (a *WhisperServiceTransport) RetrieveRawAll() (map[Filter][]*whisper.ReceivedMessage, error) { - result := make(map[Filter][]*whisper.ReceivedMessage) - - allFilters := a.filters.Filters() - for _, filter := range allFilters { - f := a.shh.GetFilter(filter.FilterID) - if f == nil { - return nil, errors.New("failed to return a filter") - } - - result[*filter] = append(result[*filter], f.Retrieve()...) - } - - return result, nil +func (a *WhisperServiceTransport) RetrieveRawAll() (map[Filter][]*whispertypes.Message, error) { + return nil, errors.New("not implemented") } // DEPRECATED -func (a *WhisperServiceTransport) RetrieveRaw(filterID string) ([]*whisper.ReceivedMessage, error) { - f := a.shh.GetFilter(filterID) - if f == nil { - return nil, errors.New("failed to return a filter") - } - return f.Retrieve(), nil +func (a *WhisperServiceTransport) RetrieveRaw(filterID string) ([]*whispertypes.Message, error) { + return a.shhAPI.GetFilterMessages(filterID) } // SendPublic sends a new message using the Whisper service. // For public filters, chat name is used as an ID as well as // a topic. -func (a *WhisperServiceTransport) SendPublic(ctx context.Context, newMessage *whisper.NewMessage, chatName string) ([]byte, error) { +func (a *WhisperServiceTransport) SendPublic(ctx context.Context, newMessage *whispertypes.NewMessage, chatName string) ([]byte, error) { if err := a.addSig(newMessage); err != nil { return nil, err } @@ -281,17 +265,17 @@ func (a *WhisperServiceTransport) SendPublic(ctx context.Context, newMessage *wh } newMessage.SymKeyID = filter.SymKeyID - newMessage.Topic = filter.Topic + newMessage.Topic = whispertypes.TopicType(filter.Topic) return a.shhAPI.Post(ctx, *newMessage) } -func (a *WhisperServiceTransport) SendPrivateWithSharedSecret(ctx context.Context, newMessage *whisper.NewMessage, publicKey *ecdsa.PublicKey, secret []byte) ([]byte, error) { +func (a *WhisperServiceTransport) SendPrivateWithSharedSecret(ctx context.Context, newMessage *whispertypes.NewMessage, publicKey *ecdsa.PublicKey, secret []byte) ([]byte, error) { if err := a.addSig(newMessage); err != nil { return nil, err } - filter, err := a.filters.LoadNegotiated(NegotiatedSecret{ + filter, err := a.filters.LoadNegotiated(whispertypes.NegotiatedSecret{ PublicKey: publicKey, Key: secret, }) @@ -300,13 +284,13 @@ func (a *WhisperServiceTransport) SendPrivateWithSharedSecret(ctx context.Contex } newMessage.SymKeyID = filter.SymKeyID - newMessage.Topic = filter.Topic + newMessage.Topic = whispertypes.TopicType(filter.Topic) newMessage.PublicKey = nil return a.shhAPI.Post(ctx, *newMessage) } -func (a *WhisperServiceTransport) SendPrivateWithPartitioned(ctx context.Context, newMessage *whisper.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) { +func (a *WhisperServiceTransport) SendPrivateWithPartitioned(ctx context.Context, newMessage *whispertypes.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) { if err := a.addSig(newMessage); err != nil { return nil, err } @@ -316,13 +300,13 @@ func (a *WhisperServiceTransport) SendPrivateWithPartitioned(ctx context.Context return nil, err } - newMessage.Topic = filter.Topic + newMessage.Topic = whispertypes.TopicType(filter.Topic) newMessage.PublicKey = crypto.FromECDSAPub(publicKey) return a.shhAPI.Post(ctx, *newMessage) } -func (a *WhisperServiceTransport) SendPrivateOnDiscovery(ctx context.Context, newMessage *whisper.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) { +func (a *WhisperServiceTransport) SendPrivateOnDiscovery(ctx context.Context, newMessage *whispertypes.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) { if err := a.addSig(newMessage); err != nil { return nil, err } @@ -333,7 +317,7 @@ func (a *WhisperServiceTransport) SendPrivateOnDiscovery(ctx context.Context, ne // TODO: change this anyway, it should be explicit // and idempotent. - newMessage.Topic = whisper.BytesToTopic( + newMessage.Topic = whispertypes.BytesToTopic( ToTopic(discoveryTopic), ) newMessage.PublicKey = crypto.FromECDSAPub(publicKey) @@ -341,7 +325,7 @@ func (a *WhisperServiceTransport) SendPrivateOnDiscovery(ctx context.Context, ne return a.shhAPI.Post(ctx, *newMessage) } -func (a *WhisperServiceTransport) addSig(newMessage *whisper.NewMessage) error { +func (a *WhisperServiceTransport) addSig(newMessage *whispertypes.NewMessage) error { sigID, err := a.keysManager.AddOrGetKeyPair(a.keysManager.privateKey) if err != nil { return err @@ -350,9 +334,9 @@ func (a *WhisperServiceTransport) addSig(newMessage *whisper.NewMessage) error { return nil } -func (a *WhisperServiceTransport) Track(identifiers [][]byte, hash []byte, newMessage whisper.NewMessage) { +func (a *WhisperServiceTransport) Track(identifiers [][]byte, hash []byte, newMessage *whispertypes.NewMessage) { if a.envelopesMonitor != nil { - a.envelopesMonitor.Add(identifiers, common.BytesToHash(hash), newMessage) + a.envelopesMonitor.Add(identifiers, statusproto.BytesToHash(hash), *newMessage) } } @@ -385,10 +369,10 @@ type MessagesRequest struct { // Topic is a regular Whisper topic. // DEPRECATED - Topic whisper.TopicType `json:"topic"` + Topic whispertypes.TopicType `json:"topic"` // Topics is a list of Whisper topics. - Topics []whisper.TopicType `json:"topics"` + Topics []whispertypes.TopicType `json:"topics"` // SymKeyID is an ID of a symmetric key to authenticate to MailServer. // It's derived from MailServer password. diff --git a/vendor/github.com/status-im/status-protocol-go/types/hash.go b/vendor/github.com/status-im/status-protocol-go/types/hash.go new file mode 100644 index 000000000..df304523f --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/types/hash.go @@ -0,0 +1,80 @@ +// Code extracted from vendor/github.com/ethereum/go-ethereum/common/types.go + +package statusproto + +import ( + "encoding/hex" +) + +const ( + // HashLength is the expected length of the hash + HashLength = 32 +) + +// Hash represents the 32 byte Keccak256 hash of arbitrary data. +type Hash [HashLength]byte + +// Encode encodes b as a hex string with 0x prefix. +func encode(b []byte) string { + enc := make([]byte, len(b)*2+2) + copy(enc, "0x") + hex.Encode(enc[2:], b) + return string(enc) +} + +// has0xPrefix validates str begins with '0x' or '0X'. +func has0xPrefix(str string) bool { + return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X') +} + +// Hex2Bytes returns the bytes represented by the hexadecimal string str. +func Hex2Bytes(str string) []byte { + h, _ := hex.DecodeString(str) + return h +} + +// FromHex returns the bytes represented by the hexadecimal string s. +// s may be prefixed with "0x". +func FromHex(s string) []byte { + if has0xPrefix(s) { + s = s[2:] + } + if len(s)%2 == 1 { + s = "0" + s + } + return Hex2Bytes(s) +} + +// HexToHash sets byte representation of s to hash. +// If b is larger than len(h), b will be cropped from the left. +func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) } + +// Hex converts a hash to a hex string. +func (h *Hash) Hex() string { return encode(h[:]) } + +// Bytes gets the byte representation of the underlying hash. +func (h Hash) Bytes() []byte { return h[:] } + +// String implements the stringer interface and is used also by the logger when +// doing full logging into a file. +func (h *Hash) String() string { + return h.Hex() +} + +// SetBytes sets the hash to the value of b. +// If b is larger than len(h), b will be cropped from the left. +func (h *Hash) SetBytes(b []byte) { + if len(b) > len(h) { + b = b[len(b)-HashLength:] + } + + copy(h[HashLength-len(b):], b) +} + +// BytesToHash sets b to hash. +// If b is larger than len(h), b will be cropped from the left. +func BytesToHash(b []byte) Hash { + var h Hash + h.SetBytes(b) + return h +} diff --git a/vendor/github.com/status-im/status-protocol-go/types/hex.go b/vendor/github.com/status-im/status-protocol-go/types/hex.go new file mode 100644 index 000000000..ad94234c3 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/types/hex.go @@ -0,0 +1,32 @@ +// Code extracted from vendor/github.com/ethereum/go-ethereum/common/hexutil/hexutil.go + +package statusproto + +import ( + "encoding/hex" + "reflect" +) + +var ( + bytesT = reflect.TypeOf(HexBytes(nil)) +) + +// HexBytes marshals/unmarshals as a JSON string with 0x prefix. +// The empty slice marshals as "0x". +type HexBytes []byte + +// MarshalText implements encoding.TextMarshaler +func (b HexBytes) MarshalText() ([]byte, error) { + result := make([]byte, len(b)*2+2) + copy(result, `0x`) + hex.Encode(result[2:], b) + return result, nil +} + +// UnmarshalJSON implements json.Unmarshaler. +func (b *HexBytes) UnmarshalJSON(input []byte) error { + if !isString(input) { + return errNonString(bytesT) + } + return wrapTypeError(b.UnmarshalText(input[1:len(input)-1]), bytesT) +} diff --git a/vendor/github.com/status-im/status-protocol-go/types/json.go b/vendor/github.com/status-im/status-protocol-go/types/json.go new file mode 100644 index 000000000..21eee539a --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/types/json.go @@ -0,0 +1,171 @@ +// Code extracted from vendor/github.com/ethereum/go-ethereum/common/hexutil/json.go + +package statusproto + +import ( + "encoding/hex" + "encoding/json" + "fmt" + "reflect" + "strconv" +) + +const ( + badNibble = ^uint64(0) + uintBits = 32 << (uint64(^uint(0)) >> 63) +) + +// Errors +var ( + ErrEmptyString = &decError{"empty hex string"} + ErrSyntax = &decError{"invalid hex string"} + ErrMissingPrefix = &decError{"hex string without 0x prefix"} + ErrOddLength = &decError{"hex string of odd length"} + ErrEmptyNumber = &decError{"hex string \"0x\""} + ErrLeadingZero = &decError{"hex number with leading zero digits"} + ErrUint64Range = &decError{"hex number > 64 bits"} + ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", uintBits)} + ErrBig256Range = &decError{"hex number > 256 bits"} +) + +type decError struct{ msg string } + +func (err decError) Error() string { return err.msg } + +func decodeNibble(in byte) uint64 { + switch { + case in >= '0' && in <= '9': + return uint64(in - '0') + case in >= 'A' && in <= 'F': + return uint64(in - 'A' + 10) + case in >= 'a' && in <= 'f': + return uint64(in - 'a' + 10) + default: + return badNibble + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (b *HexBytes) UnmarshalText(input []byte) error { + raw, err := checkText(input, true) + if err != nil { + return err + } + dec := make([]byte, len(raw)/2) + if _, err = hex.Decode(dec, raw); err != nil { + err = mapError(err) + } else { + *b = dec + } + return err +} + +// UnmarshalFixedHexText decodes the input as a string with 0x prefix. The length of out +// determines the required input length. This function is commonly used to implement the +// UnmarshalText method for fixed-size types. +func UnmarshalFixedHexText(typname string, input, out []byte) error { + raw, err := checkText(input, true) + if err != nil { + return err + } + if len(raw)/2 != len(out) { + return fmt.Errorf("hex string has length %d, want %d for %s", len(raw), len(out)*2, typname) + } + // Pre-verify syntax before modifying out. + for _, b := range raw { + if decodeNibble(b) == badNibble { + return ErrSyntax + } + } + _, err = hex.Decode(out, raw) + return err +} + +// String returns the hex encoding of b. +func (b HexBytes) String() string { + return EncodeHex(b) +} + +// EncodeHex encodes b as a hex string with 0x prefix. +func EncodeHex(b []byte) string { + enc := make([]byte, len(b)*2+2) + copy(enc, "0x") + hex.Encode(enc[2:], b) + return string(enc) +} + +// DecodeHex decodes a hex string with 0x prefix. +func DecodeHex(input string) ([]byte, error) { + if len(input) == 0 { + return nil, ErrEmptyString + } + if !has0xPrefix(input) { + return nil, ErrMissingPrefix + } + b, err := hex.DecodeString(input[2:]) + if err != nil { + err = mapError(err) + } + return b, err +} + +// MustDecodeHex decodes a hex string with 0x prefix. It panics for invalid input. +func MustDecodeHex(input string) []byte { + dec, err := DecodeHex(input) + if err != nil { + panic(err) + } + return dec +} + +func isString(input []byte) bool { + return len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' +} + +func bytesHave0xPrefix(input []byte) bool { + return len(input) >= 2 && input[0] == '0' && (input[1] == 'x' || input[1] == 'X') +} + +func checkText(input []byte, wantPrefix bool) ([]byte, error) { + if len(input) == 0 { + return nil, nil // empty strings are allowed + } + if bytesHave0xPrefix(input) { + input = input[2:] + } else if wantPrefix { + return nil, ErrMissingPrefix + } + if len(input)%2 != 0 { + return nil, ErrOddLength + } + return input, nil +} + +func mapError(err error) error { + if err, ok := err.(*strconv.NumError); ok { + switch err.Err { + case strconv.ErrRange: + return ErrUint64Range + case strconv.ErrSyntax: + return ErrSyntax + } + } + if _, ok := err.(hex.InvalidByteError); ok { + return ErrSyntax + } + if err == hex.ErrLength { + return ErrOddLength + } + return err +} + +func wrapTypeError(err error, typ reflect.Type) error { + if _, ok := err.(*decError); ok { + return &json.UnmarshalTypeError{Value: err.Error(), Type: typ} + } + return err +} + +func errNonString(typ reflect.Type) error { + return &json.UnmarshalTypeError{Value: "non-string", Type: typ} +} diff --git a/vendor/github.com/status-im/status-protocol-go/v1/membership_update_message.go b/vendor/github.com/status-im/status-protocol-go/v1/membership_update_message.go index ea9129bb7..ac8e2ed99 100644 --- a/vendor/github.com/status-im/status-protocol-go/v1/membership_update_message.go +++ b/vendor/github.com/status-im/status-protocol-go/v1/membership_update_message.go @@ -1,6 +1,24 @@ package statusproto -import "bytes" +import ( + "bytes" + "crypto/ecdsa" + "encoding/json" + "reflect" + "sort" + + "github.com/status-im/status-protocol-go/crypto" +) + +const ( + MembershipUpdateChatCreated = "chat-created" + MembershipUpdateNameChanged = "name-changed" + MembershipUpdateMembersAdded = "members-added" + MembershipUpdateMemberJoined = "member-joined" + MembershipUpdateMemberRemoved = "member-removed" + MembershipUpdateAdminsAdded = "admins-added" + MembershipUpdateAdminRemoved = "admin-removed" +) // MembershipUpdateMessage is a message used to propagate information // about group membership changes. @@ -18,6 +36,34 @@ type MembershipUpdate struct { Events []MembershipUpdateEvent `json:"events"` } +// Sign creates a signature from MembershipUpdateEvents +// and updates MembershipUpdate's signature. +// It follows the algorithm describe in the spec: +// https://github.com/status-im/specs/blob/master/status-group-chats-spec.md#signature. +func (u *MembershipUpdate) Sign(identity *ecdsa.PrivateKey) error { + sort.Slice(u.Events, func(i, j int) bool { + return u.Events[i].ClockValue < u.Events[j].ClockValue + }) + tuples := make([]interface{}, len(u.Events)) + for idx, event := range u.Events { + tuples[idx] = tupleMembershipUpdateEvent(event) + } + structureToSign := []interface{}{ + tuples, + u.ChatID, + } + data, err := json.Marshal(structureToSign) + if err != nil { + return err + } + signature, err := crypto.SignBytesAsHex(data, identity) + if err != nil { + return err + } + u.Signature = signature + return nil +} + type MembershipUpdateEvent struct { Type string `json:"type"` ClockValue int64 `json:"clockValue"` @@ -26,6 +72,62 @@ type MembershipUpdateEvent struct { Name string `json:"name,omitempty"` // name of the group chat } +func NewChatCreatedEvent(name string, clock int64) MembershipUpdateEvent { + return MembershipUpdateEvent{ + Type: MembershipUpdateChatCreated, + Name: name, + ClockValue: clock, + } +} + +func NewNameChangedEvent(name string, clock int64) MembershipUpdateEvent { + return MembershipUpdateEvent{ + Type: MembershipUpdateNameChanged, + Name: name, + ClockValue: clock, + } +} + +func NewMembersAddedEvent(members []string, clock int64) MembershipUpdateEvent { + return MembershipUpdateEvent{ + Type: MembershipUpdateMembersAdded, + Members: members, + ClockValue: clock, + } +} + +func NewMemberJoinedEvent(member string, clock int64) MembershipUpdateEvent { + return MembershipUpdateEvent{ + Type: MembershipUpdateMemberJoined, + Member: member, + ClockValue: clock, + } +} + +func NewAdminsAddedEvent(admins []string, clock int64) MembershipUpdateEvent { + return MembershipUpdateEvent{ + Type: MembershipUpdateAdminsAdded, + Members: admins, + ClockValue: clock, + } +} + +func NewMemberRemovedEvent(member string, clock int64) MembershipUpdateEvent { + return MembershipUpdateEvent{ + Type: MembershipUpdateMemberRemoved, + Member: member, + ClockValue: clock, + } +} + +func NewAdminRemovedEvent(admin string, clock int64) MembershipUpdateEvent { + return MembershipUpdateEvent{ + Type: MembershipUpdateAdminRemoved, + Member: admin, + ClockValue: clock, + } +} + // EncodeMembershipUpdateMessage encodes a MembershipUpdateMessage using Transit serialization. func EncodeMembershipUpdateMessage(value MembershipUpdateMessage) ([]byte, error) { var buf bytes.Buffer @@ -35,3 +137,91 @@ func EncodeMembershipUpdateMessage(value MembershipUpdateMessage) ([]byte, error } return buf.Bytes(), nil } + +var membershipUpdateEventFieldNamesCompat = map[string]string{ + "ClockValue": "clock-value", + "Name": "name", + "Type": "type", + "Member": "member", + "Members": "members", +} + +func tupleMembershipUpdateEvent(update MembershipUpdateEvent) [][]interface{} { + // Sort all slices first. + sort.Slice(update.Members, func(i, j int) bool { + return update.Members[i] < update.Members[j] + }) + v := reflect.ValueOf(update) + result := make([][]interface{}, 0, v.NumField()) + for i := 0; i < v.NumField(); i++ { + fieldName := v.Type().Field(i).Name + if name, exists := membershipUpdateEventFieldNamesCompat[fieldName]; exists { + fieldName = name + } + field := v.Field(i) + if !isZeroValue(field) { + result = append(result, []interface{}{fieldName, field.Interface()}) + } + } + // Sort the result lexicographically. + // We know that the first item of a tuple is a string + // because it's a field name. + sort.Slice(result, func(i, j int) bool { + return result[i][0].(string) < result[j][0].(string) + }) + return result +} + +type Group struct { + ChatID string + Admins []string + Contacts []string +} + +// ValidateEvent returns true if a given event is valid. +func (g *Group) ValidateEvent(from string, event MembershipUpdateEvent) bool { + switch event.Type { + case MembershipUpdateChatCreated: + return len(g.Admins) == 0 && len(g.Contacts) == 0 + case MembershipUpdateNameChanged: + return stringSliceContains(g.Admins, from) && len(event.Name) > 0 + case MembershipUpdateMembersAdded: + return stringSliceContains(g.Admins, from) + case MembershipUpdateMemberJoined: + return stringSliceContains(g.Contacts, from) && from == event.Member + case MembershipUpdateMemberRemoved: + // Member can remove themselves or admin can remove a member. + return from == event.Member || (stringSliceContains(g.Admins, from) && !stringSliceContains(g.Admins, event.Member)) + case MembershipUpdateAdminsAdded: + return stringSliceContains(g.Admins, from) && stringSliceSubset(event.Members, g.Contacts) + case MembershipUpdateAdminRemoved: + return stringSliceContains(g.Admins, from) && from == event.Member + default: + return false + } +} + +func stringSliceContains(slice []string, item string) bool { + for _, s := range slice { + if s == item { + return true + } + } + return false +} + +func stringSliceSubset(subset []string, set []string) bool { + for _, item1 := range set { + var found bool + for _, item2 := range subset { + if item1 == item2 { + found = true + break + } + } + if found { + return true + } + } + return false +} diff --git a/vendor/github.com/status-im/status-protocol-go/v1/message.go b/vendor/github.com/status-im/status-protocol-go/v1/message.go index 09e556e31..1c4a6470a 100644 --- a/vendor/github.com/status-im/status-protocol-go/v1/message.go +++ b/vendor/github.com/status-im/status-protocol-go/v1/message.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/golang/protobuf/proto" "github.com/pkg/errors" + statusproto "github.com/status-im/status-protocol-go/types" ) const ( @@ -152,7 +152,7 @@ func EncodeMessage(value Message) ([]byte, error) { // MessageID calculates the messageID from author's compressed public key // and not encrypted but encoded payload. -func MessageID(author *ecdsa.PublicKey, data []byte) hexutil.Bytes { +func MessageID(author *ecdsa.PublicKey, data []byte) statusproto.HexBytes { keyBytes := crypto.FromECDSAPub(author) return crypto.Keccak256(append(keyBytes, data...)) } diff --git a/vendor/github.com/status-im/status-protocol-go/v1/status_message.go b/vendor/github.com/status-im/status-protocol-go/v1/status_message.go index 5b6e52d80..ab9af9d27 100644 --- a/vendor/github.com/status-im/status-protocol-go/v1/status_message.go +++ b/vendor/github.com/status-im/status-protocol-go/v1/status_message.go @@ -4,7 +4,6 @@ import ( "crypto/ecdsa" "log" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/golang/protobuf/proto" "github.com/jinzhu/copier" @@ -12,13 +11,14 @@ import ( "github.com/status-im/status-protocol-go/applicationmetadata" "github.com/status-im/status-protocol-go/datasync" "github.com/status-im/status-protocol-go/encryption" - whisper "github.com/status-im/whisper/whisperv6" + whispertypes "github.com/status-im/status-protocol-go/transport/whisper/types" + statusproto "github.com/status-im/status-protocol-go/types" ) // StatusMessage is any Status Protocol message. type StatusMessage struct { // TransportMessage is the parsed message received from the transport layer, i.e the input - TransportMessage *whisper.Message + TransportMessage *whispertypes.Message // ParsedMessage is the parsed message by the application layer, i.e the output ParsedMessage interface{} @@ -28,7 +28,7 @@ type StatusMessage struct { DecryptedPayload []byte // ID is the canonical ID of the message - ID hexutil.Bytes + ID statusproto.HexBytes // Hash is the transport layer hash Hash []byte @@ -54,7 +54,7 @@ func (s *StatusMessage) Clone() (*StatusMessage, error) { return copy, err } -func (m *StatusMessage) HandleTransport(shhMessage *whisper.Message) error { +func (m *StatusMessage) HandleTransport(shhMessage *whispertypes.Message) error { publicKey, err := crypto.UnmarshalPubkey(shhMessage.Sig) if err != nil { return errors.Wrap(err, "failed to get signature") diff --git a/vendor/github.com/status-im/status-protocol-go/v1/value_is_zero.go b/vendor/github.com/status-im/status-protocol-go/v1/value_is_zero.go new file mode 100644 index 000000000..a3b38d0ab --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/v1/value_is_zero.go @@ -0,0 +1,11 @@ +// +build go1.13 + +package statusproto + +import "reflect" + +// isZeroValue reports whether v is the zero value for its type. +// It panics if the argument is invalid. +func isZeroValue(v reflect.Value) bool { + return v.IsZero() +} diff --git a/vendor/github.com/status-im/status-protocol-go/v1/value_is_zero_1_12.go b/vendor/github.com/status-im/status-protocol-go/v1/value_is_zero_1_12.go new file mode 100644 index 000000000..4f06ae028 --- /dev/null +++ b/vendor/github.com/status-im/status-protocol-go/v1/value_is_zero_1_12.go @@ -0,0 +1,48 @@ +// +build !go1.13 + +package statusproto + +import ( + "math" + "reflect" +) + +// isZeroValue reports whether v is the zero value for its type. +// It panics if the argument is invalid. +func isZeroValue(v reflect.Value) bool { + switch v.Kind() { + case reflect.Bool: + return !v.Bool() + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return v.Int() == 0 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + return v.Uint() == 0 + case reflect.Float32, reflect.Float64: + return math.Float64bits(v.Float()) == 0 + case reflect.Complex64, reflect.Complex128: + c := v.Complex() + return math.Float64bits(real(c)) == 0 && math.Float64bits(imag(c)) == 0 + case reflect.Array: + for i := 0; i < v.Len(); i++ { + if !isZeroValue(v.Index(i)) { + return false + } + } + return true + case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice, reflect.UnsafePointer: + return v.IsNil() + case reflect.String: + return v.Len() == 0 + case reflect.Struct: + for i := 0; i < v.NumField(); i++ { + if !isZeroValue(v.Field(i)) { + return false + } + } + return true + default: + // This should never happens, but will act as a safeguard for + // later, as a default value doesn't makes sense here. + panic(&reflect.ValueError{Method: "reflect.Value.IsZero", Kind: v.Kind()}) + } +} diff --git a/vendor/github.com/status-im/whisper/whisperv6/api.go b/vendor/github.com/status-im/whisper/whisperv6/api.go index 4fab045f5..0aa85b0ff 100644 --- a/vendor/github.com/status-im/whisper/whisperv6/api.go +++ b/vendor/github.com/status-im/whisper/whisperv6/api.go @@ -102,7 +102,7 @@ func (api *PublicWhisperAPI) SetBloomFilter(ctx context.Context, bloom hexutil.B // MarkTrustedPeer marks a peer trusted, which will allow it to send historic (expired) messages. // Note: This function is not adding new nodes, the node needs to exists as a peer. func (api *PublicWhisperAPI) MarkTrustedPeer(ctx context.Context, url string) (bool, error) { - n, err := enode.ParseV4(url) + n, err := enode.Parse(enode.ValidSchemes, url) if err != nil { return false, err } @@ -290,7 +290,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil. // send to specific node (skip PoW check) if len(req.TargetPeer) > 0 { - n, err := enode.ParseV4(req.TargetPeer) + n, err := enode.Parse(enode.ValidSchemes, req.TargetPeer) if err != nil { return nil, fmt.Errorf("failed to parse target peer: %s", err) } diff --git a/vendor/github.com/status-im/whisper/whisperv6/doc.go b/vendor/github.com/status-im/whisper/whisperv6/doc.go index 7ff7b1584..e90525a26 100644 --- a/vendor/github.com/status-im/whisper/whisperv6/doc.go +++ b/vendor/github.com/status-im/whisper/whisperv6/doc.go @@ -38,6 +38,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rlp" ) @@ -65,7 +66,7 @@ const ( signatureFlag = byte(4) TopicLength = 4 // in bytes - signatureLength = 65 // in bytes + signatureLength = crypto.SignatureLength // in bytes aesKeyLength = 32 // in bytes aesNonceLength = 12 // in bytes; for more info please see cipher.gcmStandardNonceSize & aesgcm.NonceSize() keyIDSize = 32 // in bytes diff --git a/vendor/github.com/status-im/whisper/whisperv6/envelope.go b/vendor/github.com/status-im/whisper/whisperv6/envelope.go index 3b65fdba0..38626e1be 100644 --- a/vendor/github.com/status-im/whisper/whisperv6/envelope.go +++ b/vendor/github.com/status-im/whisper/whisperv6/envelope.go @@ -27,7 +27,6 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/rlp" @@ -82,7 +81,7 @@ func (e *Envelope) Seal(options *MessageParams) error { return nil } - var target, bestBit int + var target, bestLeadingZeros int if options.PoW < 0 { // target is not set - the function should run for a period // of time specified in WorkTime param. Since we can predict @@ -92,19 +91,21 @@ func (e *Envelope) Seal(options *MessageParams) error { target = e.powToFirstBit(options.PoW) } - buf := make([]byte, 64) - h := crypto.Keccak256(e.rlpWithoutNonce()) - copy(buf[:32], h) + rlp := e.rlpWithoutNonce() + buf := make([]byte, len(rlp)+8) + copy(buf, rlp) + asAnInt := new(big.Int) finish := time.Now().Add(time.Duration(options.WorkTime) * time.Second).UnixNano() for nonce := uint64(0); time.Now().UnixNano() < finish; { for i := 0; i < 1024; i++ { - binary.BigEndian.PutUint64(buf[56:], nonce) - d := new(big.Int).SetBytes(crypto.Keccak256(buf)) - firstBit := math.FirstBitSet(d) - if firstBit > bestBit { - e.Nonce, bestBit = nonce, firstBit - if target > 0 && bestBit >= target { + binary.BigEndian.PutUint64(buf[len(rlp):], nonce) + h := crypto.Keccak256(buf) + asAnInt.SetBytes(h) + leadingZeros := 256 - asAnInt.BitLen() + if leadingZeros > bestLeadingZeros { + e.Nonce, bestLeadingZeros = nonce, leadingZeros + if target > 0 && bestLeadingZeros >= target { return nil } } @@ -112,7 +113,7 @@ func (e *Envelope) Seal(options *MessageParams) error { } } - if target > 0 && bestBit < target { + if target > 0 && bestLeadingZeros < target { return fmt.Errorf("failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime) } @@ -129,14 +130,14 @@ func (e *Envelope) PoW() float64 { } func (e *Envelope) calculatePoW(diff uint32) { - buf := make([]byte, 64) - h := crypto.Keccak256(e.rlpWithoutNonce()) - copy(buf[:32], h) - binary.BigEndian.PutUint64(buf[56:], e.Nonce) - d := new(big.Int).SetBytes(crypto.Keccak256(buf)) - firstBit := math.FirstBitSet(d) - x := gmath.Pow(2, float64(firstBit)) - x /= float64(e.size()) + rlp := e.rlpWithoutNonce() + buf := make([]byte, len(rlp)+8) + copy(buf, rlp) + binary.BigEndian.PutUint64(buf[len(rlp):], e.Nonce) + powHash := new(big.Int).SetBytes(crypto.Keccak256(buf)) + leadingZeroes := 256 - powHash.BitLen() + x := gmath.Pow(2, float64(leadingZeroes)) + x /= float64(len(rlp)) x /= float64(e.TTL + diff) e.pow = x } diff --git a/vendor/github.com/status-im/whisper/whisperv6/peer.go b/vendor/github.com/status-im/whisper/whisperv6/peer.go index b311b6da4..1a1de9bd5 100644 --- a/vendor/github.com/status-im/whisper/whisperv6/peer.go +++ b/vendor/github.com/status-im/whisper/whisperv6/peer.go @@ -134,7 +134,7 @@ func (peer *Peer) handshake() error { } } - isRemotePeerLightNode, err := s.Bool() + isRemotePeerLightNode, _ := s.Bool() if isRemotePeerLightNode && isLightNode && isRestrictedLightNodeConnection { return fmt.Errorf("peer [%x] is useless: two light client communication restricted", peer.ID()) } diff --git a/vendor/golang.org/x/net/html/atom/gen.go b/vendor/golang.org/x/net/html/atom/gen.go deleted file mode 100644 index 5d052781b..000000000 --- a/vendor/golang.org/x/net/html/atom/gen.go +++ /dev/null @@ -1,712 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -//go:generate go run gen.go -//go:generate go run gen.go -test - -package main - -import ( - "bytes" - "flag" - "fmt" - "go/format" - "io/ioutil" - "math/rand" - "os" - "sort" - "strings" -) - -// identifier converts s to a Go exported identifier. -// It converts "div" to "Div" and "accept-charset" to "AcceptCharset". -func identifier(s string) string { - b := make([]byte, 0, len(s)) - cap := true - for _, c := range s { - if c == '-' { - cap = true - continue - } - if cap && 'a' <= c && c <= 'z' { - c -= 'a' - 'A' - } - cap = false - b = append(b, byte(c)) - } - return string(b) -} - -var test = flag.Bool("test", false, "generate table_test.go") - -func genFile(name string, buf *bytes.Buffer) { - b, err := format.Source(buf.Bytes()) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - if err := ioutil.WriteFile(name, b, 0644); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} - -func main() { - flag.Parse() - - var all []string - all = append(all, elements...) - all = append(all, attributes...) - all = append(all, eventHandlers...) - all = append(all, extra...) - sort.Strings(all) - - // uniq - lists have dups - w := 0 - for _, s := range all { - if w == 0 || all[w-1] != s { - all[w] = s - w++ - } - } - all = all[:w] - - if *test { - var buf bytes.Buffer - fmt.Fprintln(&buf, "// Code generated by go generate gen.go; DO NOT EDIT.\n") - fmt.Fprintln(&buf, "//go:generate go run gen.go -test\n") - fmt.Fprintln(&buf, "package atom\n") - fmt.Fprintln(&buf, "var testAtomList = []string{") - for _, s := range all { - fmt.Fprintf(&buf, "\t%q,\n", s) - } - fmt.Fprintln(&buf, "}") - - genFile("table_test.go", &buf) - return - } - - // Find hash that minimizes table size. - var best *table - for i := 0; i < 1000000; i++ { - if best != nil && 1<<(best.k-1) < len(all) { - break - } - h := rand.Uint32() - for k := uint(0); k <= 16; k++ { - if best != nil && k >= best.k { - break - } - var t table - if t.init(h, k, all) { - best = &t - break - } - } - } - if best == nil { - fmt.Fprintf(os.Stderr, "failed to construct string table\n") - os.Exit(1) - } - - // Lay out strings, using overlaps when possible. - layout := append([]string{}, all...) - - // Remove strings that are substrings of other strings - for changed := true; changed; { - changed = false - for i, s := range layout { - if s == "" { - continue - } - for j, t := range layout { - if i != j && t != "" && strings.Contains(s, t) { - changed = true - layout[j] = "" - } - } - } - } - - // Join strings where one suffix matches another prefix. - for { - // Find best i, j, k such that layout[i][len-k:] == layout[j][:k], - // maximizing overlap length k. - besti := -1 - bestj := -1 - bestk := 0 - for i, s := range layout { - if s == "" { - continue - } - for j, t := range layout { - if i == j { - continue - } - for k := bestk + 1; k <= len(s) && k <= len(t); k++ { - if s[len(s)-k:] == t[:k] { - besti = i - bestj = j - bestk = k - } - } - } - } - if bestk > 0 { - layout[besti] += layout[bestj][bestk:] - layout[bestj] = "" - continue - } - break - } - - text := strings.Join(layout, "") - - atom := map[string]uint32{} - for _, s := range all { - off := strings.Index(text, s) - if off < 0 { - panic("lost string " + s) - } - atom[s] = uint32(off<<8 | len(s)) - } - - var buf bytes.Buffer - // Generate the Go code. - fmt.Fprintln(&buf, "// Code generated by go generate gen.go; DO NOT EDIT.\n") - fmt.Fprintln(&buf, "//go:generate go run gen.go\n") - fmt.Fprintln(&buf, "package atom\n\nconst (") - - // compute max len - maxLen := 0 - for _, s := range all { - if maxLen < len(s) { - maxLen = len(s) - } - fmt.Fprintf(&buf, "\t%s Atom = %#x\n", identifier(s), atom[s]) - } - fmt.Fprintln(&buf, ")\n") - - fmt.Fprintf(&buf, "const hash0 = %#x\n\n", best.h0) - fmt.Fprintf(&buf, "const maxAtomLen = %d\n\n", maxLen) - - fmt.Fprintf(&buf, "var table = [1<<%d]Atom{\n", best.k) - for i, s := range best.tab { - if s == "" { - continue - } - fmt.Fprintf(&buf, "\t%#x: %#x, // %s\n", i, atom[s], s) - } - fmt.Fprintf(&buf, "}\n") - datasize := (1 << best.k) * 4 - - fmt.Fprintln(&buf, "const atomText =") - textsize := len(text) - for len(text) > 60 { - fmt.Fprintf(&buf, "\t%q +\n", text[:60]) - text = text[60:] - } - fmt.Fprintf(&buf, "\t%q\n\n", text) - - genFile("table.go", &buf) - - fmt.Fprintf(os.Stdout, "%d atoms; %d string bytes + %d tables = %d total data\n", len(all), textsize, datasize, textsize+datasize) -} - -type byLen []string - -func (x byLen) Less(i, j int) bool { return len(x[i]) > len(x[j]) } -func (x byLen) Swap(i, j int) { x[i], x[j] = x[j], x[i] } -func (x byLen) Len() int { return len(x) } - -// fnv computes the FNV hash with an arbitrary starting value h. -func fnv(h uint32, s string) uint32 { - for i := 0; i < len(s); i++ { - h ^= uint32(s[i]) - h *= 16777619 - } - return h -} - -// A table represents an attempt at constructing the lookup table. -// The lookup table uses cuckoo hashing, meaning that each string -// can be found in one of two positions. -type table struct { - h0 uint32 - k uint - mask uint32 - tab []string -} - -// hash returns the two hashes for s. -func (t *table) hash(s string) (h1, h2 uint32) { - h := fnv(t.h0, s) - h1 = h & t.mask - h2 = (h >> 16) & t.mask - return -} - -// init initializes the table with the given parameters. -// h0 is the initial hash value, -// k is the number of bits of hash value to use, and -// x is the list of strings to store in the table. -// init returns false if the table cannot be constructed. -func (t *table) init(h0 uint32, k uint, x []string) bool { - t.h0 = h0 - t.k = k - t.tab = make([]string, 1< len(t.tab) { - return false - } - s := t.tab[i] - h1, h2 := t.hash(s) - j := h1 + h2 - i - if t.tab[j] != "" && !t.push(j, depth+1) { - return false - } - t.tab[j] = s - return true -} - -// The lists of element names and attribute keys were taken from -// https://html.spec.whatwg.org/multipage/indices.html#index -// as of the "HTML Living Standard - Last Updated 16 April 2018" version. - -// "command", "keygen" and "menuitem" have been removed from the spec, -// but are kept here for backwards compatibility. -var elements = []string{ - "a", - "abbr", - "address", - "area", - "article", - "aside", - "audio", - "b", - "base", - "bdi", - "bdo", - "blockquote", - "body", - "br", - "button", - "canvas", - "caption", - "cite", - "code", - "col", - "colgroup", - "command", - "data", - "datalist", - "dd", - "del", - "details", - "dfn", - "dialog", - "div", - "dl", - "dt", - "em", - "embed", - "fieldset", - "figcaption", - "figure", - "footer", - "form", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "head", - "header", - "hgroup", - "hr", - "html", - "i", - "iframe", - "img", - "input", - "ins", - "kbd", - "keygen", - "label", - "legend", - "li", - "link", - "main", - "map", - "mark", - "menu", - "menuitem", - "meta", - "meter", - "nav", - "noscript", - "object", - "ol", - "optgroup", - "option", - "output", - "p", - "param", - "picture", - "pre", - "progress", - "q", - "rp", - "rt", - "ruby", - "s", - "samp", - "script", - "section", - "select", - "slot", - "small", - "source", - "span", - "strong", - "style", - "sub", - "summary", - "sup", - "table", - "tbody", - "td", - "template", - "textarea", - "tfoot", - "th", - "thead", - "time", - "title", - "tr", - "track", - "u", - "ul", - "var", - "video", - "wbr", -} - -// https://html.spec.whatwg.org/multipage/indices.html#attributes-3 -// -// "challenge", "command", "contextmenu", "dropzone", "icon", "keytype", "mediagroup", -// "radiogroup", "spellcheck", "scoped", "seamless", "sortable" and "sorted" have been removed from the spec, -// but are kept here for backwards compatibility. -var attributes = []string{ - "abbr", - "accept", - "accept-charset", - "accesskey", - "action", - "allowfullscreen", - "allowpaymentrequest", - "allowusermedia", - "alt", - "as", - "async", - "autocomplete", - "autofocus", - "autoplay", - "challenge", - "charset", - "checked", - "cite", - "class", - "color", - "cols", - "colspan", - "command", - "content", - "contenteditable", - "contextmenu", - "controls", - "coords", - "crossorigin", - "data", - "datetime", - "default", - "defer", - "dir", - "dirname", - "disabled", - "download", - "draggable", - "dropzone", - "enctype", - "for", - "form", - "formaction", - "formenctype", - "formmethod", - "formnovalidate", - "formtarget", - "headers", - "height", - "hidden", - "high", - "href", - "hreflang", - "http-equiv", - "icon", - "id", - "inputmode", - "integrity", - "is", - "ismap", - "itemid", - "itemprop", - "itemref", - "itemscope", - "itemtype", - "keytype", - "kind", - "label", - "lang", - "list", - "loop", - "low", - "manifest", - "max", - "maxlength", - "media", - "mediagroup", - "method", - "min", - "minlength", - "multiple", - "muted", - "name", - "nomodule", - "nonce", - "novalidate", - "open", - "optimum", - "pattern", - "ping", - "placeholder", - "playsinline", - "poster", - "preload", - "radiogroup", - "readonly", - "referrerpolicy", - "rel", - "required", - "reversed", - "rows", - "rowspan", - "sandbox", - "spellcheck", - "scope", - "scoped", - "seamless", - "selected", - "shape", - "size", - "sizes", - "sortable", - "sorted", - "slot", - "span", - "spellcheck", - "src", - "srcdoc", - "srclang", - "srcset", - "start", - "step", - "style", - "tabindex", - "target", - "title", - "translate", - "type", - "typemustmatch", - "updateviacache", - "usemap", - "value", - "width", - "workertype", - "wrap", -} - -// "onautocomplete", "onautocompleteerror", "onmousewheel", -// "onshow" and "onsort" have been removed from the spec, -// but are kept here for backwards compatibility. -var eventHandlers = []string{ - "onabort", - "onautocomplete", - "onautocompleteerror", - "onauxclick", - "onafterprint", - "onbeforeprint", - "onbeforeunload", - "onblur", - "oncancel", - "oncanplay", - "oncanplaythrough", - "onchange", - "onclick", - "onclose", - "oncontextmenu", - "oncopy", - "oncuechange", - "oncut", - "ondblclick", - "ondrag", - "ondragend", - "ondragenter", - "ondragexit", - "ondragleave", - "ondragover", - "ondragstart", - "ondrop", - "ondurationchange", - "onemptied", - "onended", - "onerror", - "onfocus", - "onhashchange", - "oninput", - "oninvalid", - "onkeydown", - "onkeypress", - "onkeyup", - "onlanguagechange", - "onload", - "onloadeddata", - "onloadedmetadata", - "onloadend", - "onloadstart", - "onmessage", - "onmessageerror", - "onmousedown", - "onmouseenter", - "onmouseleave", - "onmousemove", - "onmouseout", - "onmouseover", - "onmouseup", - "onmousewheel", - "onwheel", - "onoffline", - "ononline", - "onpagehide", - "onpageshow", - "onpaste", - "onpause", - "onplay", - "onplaying", - "onpopstate", - "onprogress", - "onratechange", - "onreset", - "onresize", - "onrejectionhandled", - "onscroll", - "onsecuritypolicyviolation", - "onseeked", - "onseeking", - "onselect", - "onshow", - "onsort", - "onstalled", - "onstorage", - "onsubmit", - "onsuspend", - "ontimeupdate", - "ontoggle", - "onunhandledrejection", - "onunload", - "onvolumechange", - "onwaiting", -} - -// extra are ad-hoc values not covered by any of the lists above. -var extra = []string{ - "acronym", - "align", - "annotation", - "annotation-xml", - "applet", - "basefont", - "bgsound", - "big", - "blink", - "center", - "color", - "desc", - "face", - "font", - "foreignObject", // HTML is case-insensitive, but SVG-embedded-in-HTML is case-sensitive. - "foreignobject", - "frame", - "frameset", - "image", - "isindex", - "listing", - "malignmark", - "marquee", - "math", - "mglyph", - "mi", - "mn", - "mo", - "ms", - "mtext", - "nobr", - "noembed", - "noframes", - "plaintext", - "prompt", - "public", - "rb", - "rtc", - "spacer", - "strike", - "svg", - "system", - "tt", - "xmp", -} diff --git a/vendor/golang.org/x/net/internal/iana/gen.go b/vendor/golang.org/x/net/internal/iana/gen.go deleted file mode 100644 index 2a7661c27..000000000 --- a/vendor/golang.org/x/net/internal/iana/gen.go +++ /dev/null @@ -1,383 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -//go:generate go run gen.go - -// This program generates internet protocol constants and tables by -// reading IANA protocol registries. -package main - -import ( - "bytes" - "encoding/xml" - "fmt" - "go/format" - "io" - "io/ioutil" - "net/http" - "os" - "strconv" - "strings" -) - -var registries = []struct { - url string - parse func(io.Writer, io.Reader) error -}{ - { - "https://www.iana.org/assignments/dscp-registry/dscp-registry.xml", - parseDSCPRegistry, - }, - { - "https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml", - parseProtocolNumbers, - }, - { - "https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml", - parseAddrFamilyNumbers, - }, -} - -func main() { - var bb bytes.Buffer - fmt.Fprintf(&bb, "// go generate gen.go\n") - fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n") - fmt.Fprintf(&bb, "// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).\n") - fmt.Fprintf(&bb, `package iana // import "golang.org/x/net/internal/iana"`+"\n\n") - for _, r := range registries { - resp, err := http.Get(r.url) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - fmt.Fprintf(os.Stderr, "got HTTP status code %v for %v\n", resp.StatusCode, r.url) - os.Exit(1) - } - if err := r.parse(&bb, resp.Body); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - fmt.Fprintf(&bb, "\n") - } - b, err := format.Source(bb.Bytes()) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - if err := ioutil.WriteFile("const.go", b, 0644); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} - -func parseDSCPRegistry(w io.Writer, r io.Reader) error { - dec := xml.NewDecoder(r) - var dr dscpRegistry - if err := dec.Decode(&dr); err != nil { - return err - } - fmt.Fprintf(w, "// %s, Updated: %s\n", dr.Title, dr.Updated) - fmt.Fprintf(w, "const (\n") - for _, dr := range dr.escapeDSCP() { - fmt.Fprintf(w, "DiffServ%s = %#02x", dr.Name, dr.Value) - fmt.Fprintf(w, "// %s\n", dr.OrigName) - } - for _, er := range dr.escapeECN() { - fmt.Fprintf(w, "%s = %#02x", er.Descr, er.Value) - fmt.Fprintf(w, "// %s\n", er.OrigDescr) - } - fmt.Fprintf(w, ")\n") - return nil -} - -type dscpRegistry struct { - XMLName xml.Name `xml:"registry"` - Title string `xml:"title"` - Updated string `xml:"updated"` - Note string `xml:"note"` - Registries []struct { - Title string `xml:"title"` - Registries []struct { - Title string `xml:"title"` - Records []struct { - Name string `xml:"name"` - Space string `xml:"space"` - } `xml:"record"` - } `xml:"registry"` - Records []struct { - Value string `xml:"value"` - Descr string `xml:"description"` - } `xml:"record"` - } `xml:"registry"` -} - -type canonDSCPRecord struct { - OrigName string - Name string - Value int -} - -func (drr *dscpRegistry) escapeDSCP() []canonDSCPRecord { - var drs []canonDSCPRecord - for _, preg := range drr.Registries { - if !strings.Contains(preg.Title, "Differentiated Services Field Codepoints") { - continue - } - for _, reg := range preg.Registries { - if !strings.Contains(reg.Title, "Pool 1 Codepoints") { - continue - } - drs = make([]canonDSCPRecord, len(reg.Records)) - sr := strings.NewReplacer( - "+", "", - "-", "", - "/", "", - ".", "", - " ", "", - ) - for i, dr := range reg.Records { - s := strings.TrimSpace(dr.Name) - drs[i].OrigName = s - drs[i].Name = sr.Replace(s) - n, err := strconv.ParseUint(dr.Space, 2, 8) - if err != nil { - continue - } - drs[i].Value = int(n) << 2 - } - } - } - return drs -} - -type canonECNRecord struct { - OrigDescr string - Descr string - Value int -} - -func (drr *dscpRegistry) escapeECN() []canonECNRecord { - var ers []canonECNRecord - for _, reg := range drr.Registries { - if !strings.Contains(reg.Title, "ECN Field") { - continue - } - ers = make([]canonECNRecord, len(reg.Records)) - sr := strings.NewReplacer( - "Capable", "", - "Not-ECT", "", - "ECT(1)", "", - "ECT(0)", "", - "CE", "", - "(", "", - ")", "", - "+", "", - "-", "", - "/", "", - ".", "", - " ", "", - ) - for i, er := range reg.Records { - s := strings.TrimSpace(er.Descr) - ers[i].OrigDescr = s - ss := strings.Split(s, " ") - if len(ss) > 1 { - ers[i].Descr = strings.Join(ss[1:], " ") - } else { - ers[i].Descr = ss[0] - } - ers[i].Descr = sr.Replace(er.Descr) - n, err := strconv.ParseUint(er.Value, 2, 8) - if err != nil { - continue - } - ers[i].Value = int(n) - } - } - return ers -} - -func parseProtocolNumbers(w io.Writer, r io.Reader) error { - dec := xml.NewDecoder(r) - var pn protocolNumbers - if err := dec.Decode(&pn); err != nil { - return err - } - prs := pn.escape() - prs = append([]canonProtocolRecord{{ - Name: "IP", - Descr: "IPv4 encapsulation, pseudo protocol number", - Value: 0, - }}, prs...) - fmt.Fprintf(w, "// %s, Updated: %s\n", pn.Title, pn.Updated) - fmt.Fprintf(w, "const (\n") - for _, pr := range prs { - if pr.Name == "" { - continue - } - fmt.Fprintf(w, "Protocol%s = %d", pr.Name, pr.Value) - s := pr.Descr - if s == "" { - s = pr.OrigName - } - fmt.Fprintf(w, "// %s\n", s) - } - fmt.Fprintf(w, ")\n") - return nil -} - -type protocolNumbers struct { - XMLName xml.Name `xml:"registry"` - Title string `xml:"title"` - Updated string `xml:"updated"` - RegTitle string `xml:"registry>title"` - Note string `xml:"registry>note"` - Records []struct { - Value string `xml:"value"` - Name string `xml:"name"` - Descr string `xml:"description"` - } `xml:"registry>record"` -} - -type canonProtocolRecord struct { - OrigName string - Name string - Descr string - Value int -} - -func (pn *protocolNumbers) escape() []canonProtocolRecord { - prs := make([]canonProtocolRecord, len(pn.Records)) - sr := strings.NewReplacer( - "-in-", "in", - "-within-", "within", - "-over-", "over", - "+", "P", - "-", "", - "/", "", - ".", "", - " ", "", - ) - for i, pr := range pn.Records { - if strings.Contains(pr.Name, "Deprecated") || - strings.Contains(pr.Name, "deprecated") { - continue - } - prs[i].OrigName = pr.Name - s := strings.TrimSpace(pr.Name) - switch pr.Name { - case "ISIS over IPv4": - prs[i].Name = "ISIS" - case "manet": - prs[i].Name = "MANET" - default: - prs[i].Name = sr.Replace(s) - } - ss := strings.Split(pr.Descr, "\n") - for i := range ss { - ss[i] = strings.TrimSpace(ss[i]) - } - if len(ss) > 1 { - prs[i].Descr = strings.Join(ss, " ") - } else { - prs[i].Descr = ss[0] - } - prs[i].Value, _ = strconv.Atoi(pr.Value) - } - return prs -} - -func parseAddrFamilyNumbers(w io.Writer, r io.Reader) error { - dec := xml.NewDecoder(r) - var afn addrFamilylNumbers - if err := dec.Decode(&afn); err != nil { - return err - } - afrs := afn.escape() - fmt.Fprintf(w, "// %s, Updated: %s\n", afn.Title, afn.Updated) - fmt.Fprintf(w, "const (\n") - for _, afr := range afrs { - if afr.Name == "" { - continue - } - fmt.Fprintf(w, "AddrFamily%s = %d", afr.Name, afr.Value) - fmt.Fprintf(w, "// %s\n", afr.Descr) - } - fmt.Fprintf(w, ")\n") - return nil -} - -type addrFamilylNumbers struct { - XMLName xml.Name `xml:"registry"` - Title string `xml:"title"` - Updated string `xml:"updated"` - RegTitle string `xml:"registry>title"` - Note string `xml:"registry>note"` - Records []struct { - Value string `xml:"value"` - Descr string `xml:"description"` - } `xml:"registry>record"` -} - -type canonAddrFamilyRecord struct { - Name string - Descr string - Value int -} - -func (afn *addrFamilylNumbers) escape() []canonAddrFamilyRecord { - afrs := make([]canonAddrFamilyRecord, len(afn.Records)) - sr := strings.NewReplacer( - "IP version 4", "IPv4", - "IP version 6", "IPv6", - "Identifier", "ID", - "-", "", - "-", "", - "/", "", - ".", "", - " ", "", - ) - for i, afr := range afn.Records { - if strings.Contains(afr.Descr, "Unassigned") || - strings.Contains(afr.Descr, "Reserved") { - continue - } - afrs[i].Descr = afr.Descr - s := strings.TrimSpace(afr.Descr) - switch s { - case "IP (IP version 4)": - afrs[i].Name = "IPv4" - case "IP6 (IP version 6)": - afrs[i].Name = "IPv6" - case "AFI for L2VPN information": - afrs[i].Name = "L2VPN" - case "E.164 with NSAP format subaddress": - afrs[i].Name = "E164withSubaddress" - case "MT IP: Multi-Topology IP version 4": - afrs[i].Name = "MTIPv4" - case "MAC/24": - afrs[i].Name = "MACFinal24bits" - case "MAC/40": - afrs[i].Name = "MACFinal40bits" - case "IPv6/64": - afrs[i].Name = "IPv6Initial64bits" - default: - n := strings.Index(s, "(") - if n > 0 { - s = s[:n] - } - n = strings.Index(s, ":") - if n > 0 { - s = s[:n] - } - afrs[i].Name = sr.Replace(s) - } - afrs[i].Value, _ = strconv.Atoi(afr.Value) - } - return afrs -} diff --git a/vendor/golang.org/x/net/internal/socket/defs_aix.go b/vendor/golang.org/x/net/internal/socket/defs_aix.go deleted file mode 100644 index ae1b21c5e..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_aix.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include - -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type mmsghdr C.struct_mmsghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/internal/socket/defs_darwin.go b/vendor/golang.org/x/net/internal/socket/defs_darwin.go deleted file mode 100644 index b780bc67a..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_darwin.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include - -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/internal/socket/defs_dragonfly.go b/vendor/golang.org/x/net/internal/socket/defs_dragonfly.go deleted file mode 100644 index b780bc67a..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_dragonfly.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include - -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/internal/socket/defs_freebsd.go b/vendor/golang.org/x/net/internal/socket/defs_freebsd.go deleted file mode 100644 index b780bc67a..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_freebsd.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include - -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/internal/socket/defs_linux.go b/vendor/golang.org/x/net/internal/socket/defs_linux.go deleted file mode 100644 index 85bb7450b..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_linux.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include -#include - -#define _GNU_SOURCE -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type mmsghdr C.struct_mmsghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/internal/socket/defs_netbsd.go b/vendor/golang.org/x/net/internal/socket/defs_netbsd.go deleted file mode 100644 index 5bfdd4676..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_netbsd.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include - -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type mmsghdr C.struct_mmsghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/internal/socket/defs_openbsd.go b/vendor/golang.org/x/net/internal/socket/defs_openbsd.go deleted file mode 100644 index b780bc67a..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_openbsd.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include - -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/internal/socket/defs_solaris.go b/vendor/golang.org/x/net/internal/socket/defs_solaris.go deleted file mode 100644 index b780bc67a..000000000 --- a/vendor/golang.org/x/net/internal/socket/defs_solaris.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package socket - -/* -#include - -#include -*/ -import "C" - -type iovec C.struct_iovec - -type msghdr C.struct_msghdr - -type cmsghdr C.struct_cmsghdr - -type sockaddrInet C.struct_sockaddr_in - -type sockaddrInet6 C.struct_sockaddr_in6 - -const ( - sizeofIovec = C.sizeof_struct_iovec - sizeofMsghdr = C.sizeof_struct_msghdr - sizeofCmsghdr = C.sizeof_struct_cmsghdr - - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 -) diff --git a/vendor/golang.org/x/net/ipv4/defs_aix.go b/vendor/golang.org/x/net/ipv4/defs_aix.go deleted file mode 100644 index 0f37211c6..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_aix.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include -*/ -import "C" - -const ( - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_RECVDSTADDR = C.IP_RECVDSTADDR - sysIP_RETOPTS = C.IP_RETOPTS - // IP_RECVIF is defined on AIX but doesn't work. - // IP_RECVINTERFACE must be used instead. - sysIP_RECVIF = C.IP_RECVINTERFACE - sysIP_RECVTTL = C.IP_RECVTTL - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - - sizeofIPMreq = C.sizeof_struct_ip_mreq -) - -type ipMreq C.struct_ip_mreq diff --git a/vendor/golang.org/x/net/ipv4/defs_darwin.go b/vendor/golang.org/x/net/ipv4/defs_darwin.go deleted file mode 100644 index c8f2e05b8..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_darwin.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include - -#include -*/ -import "C" - -const ( - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_RECVDSTADDR = C.IP_RECVDSTADDR - sysIP_RETOPTS = C.IP_RETOPTS - sysIP_RECVIF = C.IP_RECVIF - sysIP_STRIPHDR = C.IP_STRIPHDR - sysIP_RECVTTL = C.IP_RECVTTL - sysIP_BOUND_IF = C.IP_BOUND_IF - sysIP_PKTINFO = C.IP_PKTINFO - sysIP_RECVPKTINFO = C.IP_RECVPKTINFO - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - sysIP_MULTICAST_VIF = C.IP_MULTICAST_VIF - sysIP_MULTICAST_IFINDEX = C.IP_MULTICAST_IFINDEX - sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP - sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP - sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE - sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE - sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP - sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP - sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP - sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP - sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE - sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE - - sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofInetPktinfo = C.sizeof_struct_in_pktinfo - - sizeofIPMreq = C.sizeof_struct_ip_mreq - sizeofIPMreqn = C.sizeof_struct_ip_mreqn - sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source - sizeofGroupReq = C.sizeof_struct_group_req - sizeofGroupSourceReq = C.sizeof_struct_group_source_req -) - -type sockaddrStorage C.struct_sockaddr_storage - -type sockaddrInet C.struct_sockaddr_in - -type inetPktinfo C.struct_in_pktinfo - -type ipMreq C.struct_ip_mreq - -type ipMreqn C.struct_ip_mreqn - -type ipMreqSource C.struct_ip_mreq_source - -type groupReq C.struct_group_req - -type groupSourceReq C.struct_group_source_req diff --git a/vendor/golang.org/x/net/ipv4/defs_dragonfly.go b/vendor/golang.org/x/net/ipv4/defs_dragonfly.go deleted file mode 100644 index f30544ea2..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_dragonfly.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include -*/ -import "C" - -const ( - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_RECVDSTADDR = C.IP_RECVDSTADDR - sysIP_RETOPTS = C.IP_RETOPTS - sysIP_RECVIF = C.IP_RECVIF - sysIP_RECVTTL = C.IP_RECVTTL - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_MULTICAST_VIF = C.IP_MULTICAST_VIF - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - - sizeofIPMreq = C.sizeof_struct_ip_mreq -) - -type ipMreq C.struct_ip_mreq diff --git a/vendor/golang.org/x/net/ipv4/defs_freebsd.go b/vendor/golang.org/x/net/ipv4/defs_freebsd.go deleted file mode 100644 index 4dd57d865..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_freebsd.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include - -#include -*/ -import "C" - -const ( - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_RECVDSTADDR = C.IP_RECVDSTADDR - sysIP_SENDSRCADDR = C.IP_SENDSRCADDR - sysIP_RETOPTS = C.IP_RETOPTS - sysIP_RECVIF = C.IP_RECVIF - sysIP_ONESBCAST = C.IP_ONESBCAST - sysIP_BINDANY = C.IP_BINDANY - sysIP_RECVTTL = C.IP_RECVTTL - sysIP_MINTTL = C.IP_MINTTL - sysIP_DONTFRAG = C.IP_DONTFRAG - sysIP_RECVTOS = C.IP_RECVTOS - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - sysIP_MULTICAST_VIF = C.IP_MULTICAST_VIF - sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP - sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP - sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE - sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE - sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP - sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP - sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP - sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP - sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE - sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE - - sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - - sizeofIPMreq = C.sizeof_struct_ip_mreq - sizeofIPMreqn = C.sizeof_struct_ip_mreqn - sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source - sizeofGroupReq = C.sizeof_struct_group_req - sizeofGroupSourceReq = C.sizeof_struct_group_source_req -) - -type sockaddrStorage C.struct_sockaddr_storage - -type sockaddrInet C.struct_sockaddr_in - -type ipMreq C.struct_ip_mreq - -type ipMreqn C.struct_ip_mreqn - -type ipMreqSource C.struct_ip_mreq_source - -type groupReq C.struct_group_req - -type groupSourceReq C.struct_group_source_req diff --git a/vendor/golang.org/x/net/ipv4/defs_linux.go b/vendor/golang.org/x/net/ipv4/defs_linux.go deleted file mode 100644 index beb11071a..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_linux.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include - -#include -#include -#include -#include -#include -*/ -import "C" - -const ( - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_ROUTER_ALERT = C.IP_ROUTER_ALERT - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RETOPTS = C.IP_RETOPTS - sysIP_PKTINFO = C.IP_PKTINFO - sysIP_PKTOPTIONS = C.IP_PKTOPTIONS - sysIP_MTU_DISCOVER = C.IP_MTU_DISCOVER - sysIP_RECVERR = C.IP_RECVERR - sysIP_RECVTTL = C.IP_RECVTTL - sysIP_RECVTOS = C.IP_RECVTOS - sysIP_MTU = C.IP_MTU - sysIP_FREEBIND = C.IP_FREEBIND - sysIP_TRANSPARENT = C.IP_TRANSPARENT - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_ORIGDSTADDR = C.IP_ORIGDSTADDR - sysIP_RECVORIGDSTADDR = C.IP_RECVORIGDSTADDR - sysIP_MINTTL = C.IP_MINTTL - sysIP_NODEFRAG = C.IP_NODEFRAG - sysIP_UNICAST_IF = C.IP_UNICAST_IF - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE - sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE - sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP - sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP - sysIP_MSFILTER = C.IP_MSFILTER - sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP - sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP - sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP - sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP - sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE - sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE - sysMCAST_MSFILTER = C.MCAST_MSFILTER - sysIP_MULTICAST_ALL = C.IP_MULTICAST_ALL - - //sysIP_PMTUDISC_DONT = C.IP_PMTUDISC_DONT - //sysIP_PMTUDISC_WANT = C.IP_PMTUDISC_WANT - //sysIP_PMTUDISC_DO = C.IP_PMTUDISC_DO - //sysIP_PMTUDISC_PROBE = C.IP_PMTUDISC_PROBE - //sysIP_PMTUDISC_INTERFACE = C.IP_PMTUDISC_INTERFACE - //sysIP_PMTUDISC_OMIT = C.IP_PMTUDISC_OMIT - - sysICMP_FILTER = C.ICMP_FILTER - - sysSO_EE_ORIGIN_NONE = C.SO_EE_ORIGIN_NONE - sysSO_EE_ORIGIN_LOCAL = C.SO_EE_ORIGIN_LOCAL - sysSO_EE_ORIGIN_ICMP = C.SO_EE_ORIGIN_ICMP - sysSO_EE_ORIGIN_ICMP6 = C.SO_EE_ORIGIN_ICMP6 - sysSO_EE_ORIGIN_TXSTATUS = C.SO_EE_ORIGIN_TXSTATUS - sysSO_EE_ORIGIN_TIMESTAMPING = C.SO_EE_ORIGIN_TIMESTAMPING - - sysSOL_SOCKET = C.SOL_SOCKET - sysSO_ATTACH_FILTER = C.SO_ATTACH_FILTER - - sizeofKernelSockaddrStorage = C.sizeof_struct___kernel_sockaddr_storage - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofInetPktinfo = C.sizeof_struct_in_pktinfo - sizeofSockExtendedErr = C.sizeof_struct_sock_extended_err - - sizeofIPMreq = C.sizeof_struct_ip_mreq - sizeofIPMreqn = C.sizeof_struct_ip_mreqn - sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source - sizeofGroupReq = C.sizeof_struct_group_req - sizeofGroupSourceReq = C.sizeof_struct_group_source_req - - sizeofICMPFilter = C.sizeof_struct_icmp_filter - - sizeofSockFprog = C.sizeof_struct_sock_fprog -) - -type kernelSockaddrStorage C.struct___kernel_sockaddr_storage - -type sockaddrInet C.struct_sockaddr_in - -type inetPktinfo C.struct_in_pktinfo - -type sockExtendedErr C.struct_sock_extended_err - -type ipMreq C.struct_ip_mreq - -type ipMreqn C.struct_ip_mreqn - -type ipMreqSource C.struct_ip_mreq_source - -type groupReq C.struct_group_req - -type groupSourceReq C.struct_group_source_req - -type icmpFilter C.struct_icmp_filter - -type sockFProg C.struct_sock_fprog - -type sockFilter C.struct_sock_filter diff --git a/vendor/golang.org/x/net/ipv4/defs_netbsd.go b/vendor/golang.org/x/net/ipv4/defs_netbsd.go deleted file mode 100644 index 8f8af1b89..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_netbsd.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include -*/ -import "C" - -const ( - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_RECVDSTADDR = C.IP_RECVDSTADDR - sysIP_RETOPTS = C.IP_RETOPTS - sysIP_RECVIF = C.IP_RECVIF - sysIP_RECVTTL = C.IP_RECVTTL - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - - sizeofIPMreq = C.sizeof_struct_ip_mreq -) - -type ipMreq C.struct_ip_mreq diff --git a/vendor/golang.org/x/net/ipv4/defs_openbsd.go b/vendor/golang.org/x/net/ipv4/defs_openbsd.go deleted file mode 100644 index 8f8af1b89..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_openbsd.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include -*/ -import "C" - -const ( - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_RECVDSTADDR = C.IP_RECVDSTADDR - sysIP_RETOPTS = C.IP_RETOPTS - sysIP_RECVIF = C.IP_RECVIF - sysIP_RECVTTL = C.IP_RECVTTL - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - - sizeofIPMreq = C.sizeof_struct_ip_mreq -) - -type ipMreq C.struct_ip_mreq diff --git a/vendor/golang.org/x/net/ipv4/defs_solaris.go b/vendor/golang.org/x/net/ipv4/defs_solaris.go deleted file mode 100644 index aeb33e9c8..000000000 --- a/vendor/golang.org/x/net/ipv4/defs_solaris.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// +godefs map struct_in_addr [4]byte /* in_addr */ - -package ipv4 - -/* -#include - -#include -*/ -import "C" - -const ( - sysIP_OPTIONS = C.IP_OPTIONS - sysIP_HDRINCL = C.IP_HDRINCL - sysIP_TOS = C.IP_TOS - sysIP_TTL = C.IP_TTL - sysIP_RECVOPTS = C.IP_RECVOPTS - sysIP_RECVRETOPTS = C.IP_RECVRETOPTS - sysIP_RECVDSTADDR = C.IP_RECVDSTADDR - sysIP_RETOPTS = C.IP_RETOPTS - sysIP_RECVIF = C.IP_RECVIF - sysIP_RECVSLLA = C.IP_RECVSLLA - sysIP_RECVTTL = C.IP_RECVTTL - - sysIP_MULTICAST_IF = C.IP_MULTICAST_IF - sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL - sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP - sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP - sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP - sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE - sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE - sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP - sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP - sysIP_NEXTHOP = C.IP_NEXTHOP - - sysIP_PKTINFO = C.IP_PKTINFO - sysIP_RECVPKTINFO = C.IP_RECVPKTINFO - sysIP_DONTFRAG = C.IP_DONTFRAG - - sysIP_BOUND_IF = C.IP_BOUND_IF - sysIP_UNSPEC_SRC = C.IP_UNSPEC_SRC - sysIP_BROADCAST_TTL = C.IP_BROADCAST_TTL - sysIP_DHCPINIT_IF = C.IP_DHCPINIT_IF - - sysIP_REUSEADDR = C.IP_REUSEADDR - sysIP_DONTROUTE = C.IP_DONTROUTE - sysIP_BROADCAST = C.IP_BROADCAST - - sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP - sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP - sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE - sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE - sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP - sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP - - sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage - sizeofSockaddrInet = C.sizeof_struct_sockaddr_in - sizeofInetPktinfo = C.sizeof_struct_in_pktinfo - - sizeofIPMreq = C.sizeof_struct_ip_mreq - sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source - sizeofGroupReq = C.sizeof_struct_group_req - sizeofGroupSourceReq = C.sizeof_struct_group_source_req -) - -type sockaddrStorage C.struct_sockaddr_storage - -type sockaddrInet C.struct_sockaddr_in - -type inetPktinfo C.struct_in_pktinfo - -type ipMreq C.struct_ip_mreq - -type ipMreqSource C.struct_ip_mreq_source - -type groupReq C.struct_group_req - -type groupSourceReq C.struct_group_source_req diff --git a/vendor/golang.org/x/net/ipv4/gen.go b/vendor/golang.org/x/net/ipv4/gen.go deleted file mode 100644 index 1bb1737f6..000000000 --- a/vendor/golang.org/x/net/ipv4/gen.go +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -//go:generate go run gen.go - -// This program generates system adaptation constants and types, -// internet protocol constants and tables by reading template files -// and IANA protocol registries. -package main - -import ( - "bytes" - "encoding/xml" - "fmt" - "go/format" - "io" - "io/ioutil" - "net/http" - "os" - "os/exec" - "runtime" - "strconv" - "strings" -) - -func main() { - if err := genzsys(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - if err := geniana(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} - -func genzsys() error { - defs := "defs_" + runtime.GOOS + ".go" - f, err := os.Open(defs) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - f.Close() - cmd := exec.Command("go", "tool", "cgo", "-godefs", defs) - b, err := cmd.Output() - if err != nil { - return err - } - b, err = format.Source(b) - if err != nil { - return err - } - zsys := "zsys_" + runtime.GOOS + ".go" - switch runtime.GOOS { - case "freebsd", "linux": - zsys = "zsys_" + runtime.GOOS + "_" + runtime.GOARCH + ".go" - } - if err := ioutil.WriteFile(zsys, b, 0644); err != nil { - return err - } - return nil -} - -var registries = []struct { - url string - parse func(io.Writer, io.Reader) error -}{ - { - "https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xml", - parseICMPv4Parameters, - }, -} - -func geniana() error { - var bb bytes.Buffer - fmt.Fprintf(&bb, "// go generate gen.go\n") - fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n") - fmt.Fprintf(&bb, "package ipv4\n\n") - for _, r := range registries { - resp, err := http.Get(r.url) - if err != nil { - return err - } - defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("got HTTP status code %v for %v\n", resp.StatusCode, r.url) - } - if err := r.parse(&bb, resp.Body); err != nil { - return err - } - fmt.Fprintf(&bb, "\n") - } - b, err := format.Source(bb.Bytes()) - if err != nil { - return err - } - if err := ioutil.WriteFile("iana.go", b, 0644); err != nil { - return err - } - return nil -} - -func parseICMPv4Parameters(w io.Writer, r io.Reader) error { - dec := xml.NewDecoder(r) - var icp icmpv4Parameters - if err := dec.Decode(&icp); err != nil { - return err - } - prs := icp.escape() - fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated) - fmt.Fprintf(w, "const (\n") - for _, pr := range prs { - if pr.Descr == "" { - continue - } - fmt.Fprintf(w, "ICMPType%s ICMPType = %d", pr.Descr, pr.Value) - fmt.Fprintf(w, "// %s\n", pr.OrigDescr) - } - fmt.Fprintf(w, ")\n\n") - fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated) - fmt.Fprintf(w, "var icmpTypes = map[ICMPType]string{\n") - for _, pr := range prs { - if pr.Descr == "" { - continue - } - fmt.Fprintf(w, "%d: %q,\n", pr.Value, strings.ToLower(pr.OrigDescr)) - } - fmt.Fprintf(w, "}\n") - return nil -} - -type icmpv4Parameters struct { - XMLName xml.Name `xml:"registry"` - Title string `xml:"title"` - Updated string `xml:"updated"` - Registries []struct { - Title string `xml:"title"` - Records []struct { - Value string `xml:"value"` - Descr string `xml:"description"` - } `xml:"record"` - } `xml:"registry"` -} - -type canonICMPv4ParamRecord struct { - OrigDescr string - Descr string - Value int -} - -func (icp *icmpv4Parameters) escape() []canonICMPv4ParamRecord { - id := -1 - for i, r := range icp.Registries { - if strings.Contains(r.Title, "Type") || strings.Contains(r.Title, "type") { - id = i - break - } - } - if id < 0 { - return nil - } - prs := make([]canonICMPv4ParamRecord, len(icp.Registries[id].Records)) - sr := strings.NewReplacer( - "Messages", "", - "Message", "", - "ICMP", "", - "+", "P", - "-", "", - "/", "", - ".", "", - " ", "", - ) - for i, pr := range icp.Registries[id].Records { - if strings.Contains(pr.Descr, "Reserved") || - strings.Contains(pr.Descr, "Unassigned") || - strings.Contains(pr.Descr, "Deprecated") || - strings.Contains(pr.Descr, "Experiment") || - strings.Contains(pr.Descr, "experiment") { - continue - } - ss := strings.Split(pr.Descr, "\n") - if len(ss) > 1 { - prs[i].Descr = strings.Join(ss, " ") - } else { - prs[i].Descr = ss[0] - } - s := strings.TrimSpace(prs[i].Descr) - prs[i].OrigDescr = s - prs[i].Descr = sr.Replace(s) - prs[i].Value, _ = strconv.Atoi(pr.Value) - } - return prs -} diff --git a/vendor/golang.org/x/sys/unix/mkasm_darwin.go b/vendor/golang.org/x/sys/unix/mkasm_darwin.go deleted file mode 100644 index 4548b993d..000000000 --- a/vendor/golang.org/x/sys/unix/mkasm_darwin.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2018 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go. -//This program must be run after mksyscall.go. -package main - -import ( - "bytes" - "fmt" - "io/ioutil" - "log" - "os" - "strings" -) - -func main() { - in1, err := ioutil.ReadFile("syscall_darwin.go") - if err != nil { - log.Fatalf("can't open syscall_darwin.go: %s", err) - } - arch := os.Args[1] - in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch)) - if err != nil { - log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err) - } - in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch)) - if err != nil { - log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err) - } - in := string(in1) + string(in2) + string(in3) - - trampolines := map[string]bool{} - - var out bytes.Buffer - - fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " ")) - fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n") - fmt.Fprintf(&out, "\n") - fmt.Fprintf(&out, "// +build go1.12\n") - fmt.Fprintf(&out, "\n") - fmt.Fprintf(&out, "#include \"textflag.h\"\n") - for _, line := range strings.Split(in, "\n") { - if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") { - continue - } - fn := line[5 : len(line)-13] - if !trampolines[fn] { - trampolines[fn] = true - fmt.Fprintf(&out, "TEXT ·%s_trampoline(SB),NOSPLIT,$0-0\n", fn) - fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn) - } - } - err = ioutil.WriteFile(fmt.Sprintf("zsyscall_darwin_%s.s", arch), out.Bytes(), 0644) - if err != nil { - log.Fatalf("can't write zsyscall_darwin_%s.s: %s", arch, err) - } -} diff --git a/vendor/golang.org/x/sys/unix/mkpost.go b/vendor/golang.org/x/sys/unix/mkpost.go deleted file mode 100644 index eb4332059..000000000 --- a/vendor/golang.org/x/sys/unix/mkpost.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// mkpost processes the output of cgo -godefs to -// modify the generated types. It is used to clean up -// the sys API in an architecture specific manner. -// -// mkpost is run after cgo -godefs; see README.md. -package main - -import ( - "bytes" - "fmt" - "go/format" - "io/ioutil" - "log" - "os" - "regexp" -) - -func main() { - // Get the OS and architecture (using GOARCH_TARGET if it exists) - goos := os.Getenv("GOOS") - goarch := os.Getenv("GOARCH_TARGET") - if goarch == "" { - goarch = os.Getenv("GOARCH") - } - // Check that we are using the Docker-based build system if we should be. - if goos == "linux" { - if os.Getenv("GOLANG_SYS_BUILD") != "docker" { - os.Stderr.WriteString("In the Docker-based build system, mkpost should not be called directly.\n") - os.Stderr.WriteString("See README.md\n") - os.Exit(1) - } - } - - b, err := ioutil.ReadAll(os.Stdin) - if err != nil { - log.Fatal(err) - } - - if goos == "aix" { - // Replace type of Atim, Mtim and Ctim by Timespec in Stat_t - // to avoid having both StTimespec and Timespec. - sttimespec := regexp.MustCompile(`_Ctype_struct_st_timespec`) - b = sttimespec.ReplaceAll(b, []byte("Timespec")) - } - - // Intentionally export __val fields in Fsid and Sigset_t - valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__(bits|val)(\s+\S+\s+)}`) - b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$4}")) - - // Intentionally export __fds_bits field in FdSet - fdSetRegex := regexp.MustCompile(`type (FdSet) struct {(\s+)X__fds_bits(\s+\S+\s+)}`) - b = fdSetRegex.ReplaceAll(b, []byte("type $1 struct {${2}Bits$3}")) - - // If we have empty Ptrace structs, we should delete them. Only s390x emits - // nonempty Ptrace structs. - ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`) - b = ptraceRexexp.ReplaceAll(b, nil) - - // Replace the control_regs union with a blank identifier for now. - controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`) - b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64")) - - // Remove fields that are added by glibc - // Note that this is unstable as the identifers are private. - removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`) - b = removeFieldsRegex.ReplaceAll(b, []byte("_")) - - // Convert [65]int8 to [65]byte in Utsname members to simplify - // conversion to string; see golang.org/issue/20753 - convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`) - b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte")) - - // Convert [1024]int8 to [1024]byte in Ptmget members - convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`) - b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte")) - - // Remove spare fields (e.g. in Statx_t) - spareFieldsRegex := regexp.MustCompile(`X__spare\S*`) - b = spareFieldsRegex.ReplaceAll(b, []byte("_")) - - // Remove cgo padding fields - removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`) - b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_")) - - // Remove padding, hidden, or unused fields - removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`) - b = removeFieldsRegex.ReplaceAll(b, []byte("_")) - - // Remove the first line of warning from cgo - b = b[bytes.IndexByte(b, '\n')+1:] - // Modify the command in the header to include: - // mkpost, our own warning, and a build tag. - replacement := fmt.Sprintf(`$1 | go run mkpost.go -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s,%s`, goarch, goos) - cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`) - b = cgoCommandRegex.ReplaceAll(b, []byte(replacement)) - - // Rename Stat_t time fields - if goos == "freebsd" && goarch == "386" { - // Hide Stat_t.[AMCB]tim_ext fields - renameStatTimeExtFieldsRegex := regexp.MustCompile(`[AMCB]tim_ext`) - b = renameStatTimeExtFieldsRegex.ReplaceAll(b, []byte("_")) - } - renameStatTimeFieldsRegex := regexp.MustCompile(`([AMCB])(?:irth)?time?(?:spec)?\s+(Timespec|StTimespec)`) - b = renameStatTimeFieldsRegex.ReplaceAll(b, []byte("${1}tim ${2}")) - - // gofmt - b, err = format.Source(b) - if err != nil { - log.Fatal(err) - } - - os.Stdout.Write(b) -} diff --git a/vendor/golang.org/x/sys/unix/mksyscall.go b/vendor/golang.org/x/sys/unix/mksyscall.go deleted file mode 100644 index e4af9424e..000000000 --- a/vendor/golang.org/x/sys/unix/mksyscall.go +++ /dev/null @@ -1,407 +0,0 @@ -// Copyright 2018 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -This program reads a file containing function prototypes -(like syscall_darwin.go) and generates system call bodies. -The prototypes are marked by lines beginning with "//sys" -and read like func declarations if //sys is replaced by func, but: - * The parameter lists must give a name for each argument. - This includes return parameters. - * The parameter lists must give a type for each argument: - the (x, y, z int) shorthand is not allowed. - * If the return parameter is an error number, it must be named errno. - -A line beginning with //sysnb is like //sys, except that the -goroutine will not be suspended during the execution of the system -call. This must only be used for system calls which can never -block, as otherwise the system call could cause all goroutines to -hang. -*/ -package main - -import ( - "bufio" - "flag" - "fmt" - "os" - "regexp" - "strings" -) - -var ( - b32 = flag.Bool("b32", false, "32bit big-endian") - l32 = flag.Bool("l32", false, "32bit little-endian") - plan9 = flag.Bool("plan9", false, "plan9") - openbsd = flag.Bool("openbsd", false, "openbsd") - netbsd = flag.Bool("netbsd", false, "netbsd") - dragonfly = flag.Bool("dragonfly", false, "dragonfly") - arm = flag.Bool("arm", false, "arm") // 64-bit value should use (even, odd)-pair - tags = flag.String("tags", "", "build tags") - filename = flag.String("output", "", "output file name (standard output if omitted)") -) - -// cmdLine returns this programs's commandline arguments -func cmdLine() string { - return "go run mksyscall.go " + strings.Join(os.Args[1:], " ") -} - -// buildTags returns build tags -func buildTags() string { - return *tags -} - -// Param is function parameter -type Param struct { - Name string - Type string -} - -// usage prints the program usage -func usage() { - fmt.Fprintf(os.Stderr, "usage: go run mksyscall.go [-b32 | -l32] [-tags x,y] [file ...]\n") - os.Exit(1) -} - -// parseParamList parses parameter list and returns a slice of parameters -func parseParamList(list string) []string { - list = strings.TrimSpace(list) - if list == "" { - return []string{} - } - return regexp.MustCompile(`\s*,\s*`).Split(list, -1) -} - -// parseParam splits a parameter into name and type -func parseParam(p string) Param { - ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p) - if ps == nil { - fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p) - os.Exit(1) - } - return Param{ps[1], ps[2]} -} - -func main() { - // Get the OS and architecture (using GOARCH_TARGET if it exists) - goos := os.Getenv("GOOS") - if goos == "" { - fmt.Fprintln(os.Stderr, "GOOS not defined in environment") - os.Exit(1) - } - goarch := os.Getenv("GOARCH_TARGET") - if goarch == "" { - goarch = os.Getenv("GOARCH") - } - - // Check that we are using the Docker-based build system if we should - if goos == "linux" { - if os.Getenv("GOLANG_SYS_BUILD") != "docker" { - fmt.Fprintf(os.Stderr, "In the Docker-based build system, mksyscall should not be called directly.\n") - fmt.Fprintf(os.Stderr, "See README.md\n") - os.Exit(1) - } - } - - flag.Usage = usage - flag.Parse() - if len(flag.Args()) <= 0 { - fmt.Fprintf(os.Stderr, "no files to parse provided\n") - usage() - } - - endianness := "" - if *b32 { - endianness = "big-endian" - } else if *l32 { - endianness = "little-endian" - } - - libc := false - if goos == "darwin" && strings.Contains(buildTags(), ",go1.12") { - libc = true - } - trampolines := map[string]bool{} - - text := "" - for _, path := range flag.Args() { - file, err := os.Open(path) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - s := bufio.NewScanner(file) - for s.Scan() { - t := s.Text() - t = strings.TrimSpace(t) - t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `) - nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t) - if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil { - continue - } - - // Line must be of the form - // func Open(path string, mode int, perm int) (fd int, errno error) - // Split into name, in params, out params. - f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$`).FindStringSubmatch(t) - if f == nil { - fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t) - os.Exit(1) - } - funct, inps, outps, sysname := f[2], f[3], f[4], f[5] - - // ClockGettime doesn't have a syscall number on Darwin, only generate libc wrappers. - if goos == "darwin" && !libc && funct == "ClockGettime" { - continue - } - - // Split argument lists on comma. - in := parseParamList(inps) - out := parseParamList(outps) - - // Try in vain to keep people from editing this file. - // The theory is that they jump into the middle of the file - // without reading the header. - text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n" - - // Go function header. - outDecl := "" - if len(out) > 0 { - outDecl = fmt.Sprintf(" (%s)", strings.Join(out, ", ")) - } - text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outDecl) - - // Check if err return available - errvar := "" - for _, param := range out { - p := parseParam(param) - if p.Type == "error" { - errvar = p.Name - break - } - } - - // Prepare arguments to Syscall. - var args []string - n := 0 - for _, param := range in { - p := parseParam(param) - if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil { - args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))") - } else if p.Type == "string" && errvar != "" { - text += fmt.Sprintf("\tvar _p%d *byte\n", n) - text += fmt.Sprintf("\t_p%d, %s = BytePtrFromString(%s)\n", n, errvar, p.Name) - text += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar) - args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n)) - n++ - } else if p.Type == "string" { - fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n") - text += fmt.Sprintf("\tvar _p%d *byte\n", n) - text += fmt.Sprintf("\t_p%d, _ = BytePtrFromString(%s)\n", n, p.Name) - args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n)) - n++ - } else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil { - // Convert slice into pointer, length. - // Have to be careful not to take address of &a[0] if len == 0: - // pass dummy pointer in that case. - // Used to pass nil, but some OSes or simulators reject write(fd, nil, 0). - text += fmt.Sprintf("\tvar _p%d unsafe.Pointer\n", n) - text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = unsafe.Pointer(&%s[0])\n\t}", p.Name, n, p.Name) - text += fmt.Sprintf(" else {\n\t\t_p%d = unsafe.Pointer(&_zero)\n\t}\n", n) - args = append(args, fmt.Sprintf("uintptr(_p%d)", n), fmt.Sprintf("uintptr(len(%s))", p.Name)) - n++ - } else if p.Type == "int64" && (*openbsd || *netbsd) { - args = append(args, "0") - if endianness == "big-endian" { - args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name)) - } else if endianness == "little-endian" { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name)) - } else { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name)) - } - } else if p.Type == "int64" && *dragonfly { - if regexp.MustCompile(`^(?i)extp(read|write)`).FindStringSubmatch(funct) == nil { - args = append(args, "0") - } - if endianness == "big-endian" { - args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name)) - } else if endianness == "little-endian" { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name)) - } else { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name)) - } - } else if (p.Type == "int64" || p.Type == "uint64") && endianness != "" { - if len(args)%2 == 1 && *arm { - // arm abi specifies 64-bit argument uses - // (even, odd) pair - args = append(args, "0") - } - if endianness == "big-endian" { - args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name)) - } else { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name)) - } - } else { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name)) - } - } - - // Determine which form to use; pad args with zeros. - asm := "Syscall" - if nonblock != nil { - if errvar == "" && goos == "linux" { - asm = "RawSyscallNoError" - } else { - asm = "RawSyscall" - } - } else { - if errvar == "" && goos == "linux" { - asm = "SyscallNoError" - } - } - if len(args) <= 3 { - for len(args) < 3 { - args = append(args, "0") - } - } else if len(args) <= 6 { - asm += "6" - for len(args) < 6 { - args = append(args, "0") - } - } else if len(args) <= 9 { - asm += "9" - for len(args) < 9 { - args = append(args, "0") - } - } else { - fmt.Fprintf(os.Stderr, "%s:%s too many arguments to system call\n", path, funct) - } - - // System call number. - if sysname == "" { - sysname = "SYS_" + funct - sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`) - sysname = strings.ToUpper(sysname) - } - - var libcFn string - if libc { - asm = "syscall_" + strings.ToLower(asm[:1]) + asm[1:] // internal syscall call - sysname = strings.TrimPrefix(sysname, "SYS_") // remove SYS_ - sysname = strings.ToLower(sysname) // lowercase - if sysname == "getdirentries64" { - // Special case - libSystem name and - // raw syscall name don't match. - sysname = "__getdirentries64" - } - libcFn = sysname - sysname = "funcPC(libc_" + sysname + "_trampoline)" - } - - // Actual call. - arglist := strings.Join(args, ", ") - call := fmt.Sprintf("%s(%s, %s)", asm, sysname, arglist) - - // Assign return values. - body := "" - ret := []string{"_", "_", "_"} - doErrno := false - for i := 0; i < len(out); i++ { - p := parseParam(out[i]) - reg := "" - if p.Name == "err" && !*plan9 { - reg = "e1" - ret[2] = reg - doErrno = true - } else if p.Name == "err" && *plan9 { - ret[0] = "r0" - ret[2] = "e1" - break - } else { - reg = fmt.Sprintf("r%d", i) - ret[i] = reg - } - if p.Type == "bool" { - reg = fmt.Sprintf("%s != 0", reg) - } - if p.Type == "int64" && endianness != "" { - // 64-bit number in r1:r0 or r0:r1. - if i+2 > len(out) { - fmt.Fprintf(os.Stderr, "%s:%s not enough registers for int64 return\n", path, funct) - } - if endianness == "big-endian" { - reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i, i+1) - } else { - reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i+1, i) - } - ret[i] = fmt.Sprintf("r%d", i) - ret[i+1] = fmt.Sprintf("r%d", i+1) - } - if reg != "e1" || *plan9 { - body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg) - } - } - if ret[0] == "_" && ret[1] == "_" && ret[2] == "_" { - text += fmt.Sprintf("\t%s\n", call) - } else { - if errvar == "" && goos == "linux" { - // raw syscall without error on Linux, see golang.org/issue/22924 - text += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], call) - } else { - text += fmt.Sprintf("\t%s, %s, %s := %s\n", ret[0], ret[1], ret[2], call) - } - } - text += body - - if *plan9 && ret[2] == "e1" { - text += "\tif int32(r0) == -1 {\n" - text += "\t\terr = e1\n" - text += "\t}\n" - } else if doErrno { - text += "\tif e1 != 0 {\n" - text += "\t\terr = errnoErr(e1)\n" - text += "\t}\n" - } - text += "\treturn\n" - text += "}\n\n" - - if libc && !trampolines[libcFn] { - // some system calls share a trampoline, like read and readlen. - trampolines[libcFn] = true - // Declare assembly trampoline. - text += fmt.Sprintf("func libc_%s_trampoline()\n", libcFn) - // Assembly trampoline calls the libc_* function, which this magic - // redirects to use the function from libSystem. - text += fmt.Sprintf("//go:linkname libc_%s libc_%s\n", libcFn, libcFn) - text += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"/usr/lib/libSystem.B.dylib\"\n", libcFn, libcFn) - text += "\n" - } - } - if err := s.Err(); err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - file.Close() - } - fmt.Printf(srcTemplate, cmdLine(), buildTags(), text) -} - -const srcTemplate = `// %s -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s - -package unix - -import ( - "syscall" - "unsafe" -) - -var _ syscall.Errno - -%s -` diff --git a/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go b/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go deleted file mode 100644 index 3be3cdfc3..000000000 --- a/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go +++ /dev/null @@ -1,415 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -This program reads a file containing function prototypes -(like syscall_aix.go) and generates system call bodies. -The prototypes are marked by lines beginning with "//sys" -and read like func declarations if //sys is replaced by func, but: - * The parameter lists must give a name for each argument. - This includes return parameters. - * The parameter lists must give a type for each argument: - the (x, y, z int) shorthand is not allowed. - * If the return parameter is an error number, it must be named err. - * If go func name needs to be different than its libc name, - * or the function is not in libc, name could be specified - * at the end, after "=" sign, like - //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt -*/ -package main - -import ( - "bufio" - "flag" - "fmt" - "os" - "regexp" - "strings" -) - -var ( - b32 = flag.Bool("b32", false, "32bit big-endian") - l32 = flag.Bool("l32", false, "32bit little-endian") - aix = flag.Bool("aix", false, "aix") - tags = flag.String("tags", "", "build tags") -) - -// cmdLine returns this programs's commandline arguments -func cmdLine() string { - return "go run mksyscall_aix_ppc.go " + strings.Join(os.Args[1:], " ") -} - -// buildTags returns build tags -func buildTags() string { - return *tags -} - -// Param is function parameter -type Param struct { - Name string - Type string -} - -// usage prints the program usage -func usage() { - fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc.go [-b32 | -l32] [-tags x,y] [file ...]\n") - os.Exit(1) -} - -// parseParamList parses parameter list and returns a slice of parameters -func parseParamList(list string) []string { - list = strings.TrimSpace(list) - if list == "" { - return []string{} - } - return regexp.MustCompile(`\s*,\s*`).Split(list, -1) -} - -// parseParam splits a parameter into name and type -func parseParam(p string) Param { - ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p) - if ps == nil { - fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p) - os.Exit(1) - } - return Param{ps[1], ps[2]} -} - -func main() { - flag.Usage = usage - flag.Parse() - if len(flag.Args()) <= 0 { - fmt.Fprintf(os.Stderr, "no files to parse provided\n") - usage() - } - - endianness := "" - if *b32 { - endianness = "big-endian" - } else if *l32 { - endianness = "little-endian" - } - - pack := "" - text := "" - cExtern := "/*\n#include \n#include \n" - for _, path := range flag.Args() { - file, err := os.Open(path) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - s := bufio.NewScanner(file) - for s.Scan() { - t := s.Text() - t = strings.TrimSpace(t) - t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `) - if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" { - pack = p[1] - } - nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t) - if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil { - continue - } - - // Line must be of the form - // func Open(path string, mode int, perm int) (fd int, err error) - // Split into name, in params, out params. - f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t) - if f == nil { - fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t) - os.Exit(1) - } - funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6] - - // Split argument lists on comma. - in := parseParamList(inps) - out := parseParamList(outps) - - inps = strings.Join(in, ", ") - outps = strings.Join(out, ", ") - - // Try in vain to keep people from editing this file. - // The theory is that they jump into the middle of the file - // without reading the header. - text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n" - - // Check if value return, err return available - errvar := "" - retvar := "" - rettype := "" - for _, param := range out { - p := parseParam(param) - if p.Type == "error" { - errvar = p.Name - } else { - retvar = p.Name - rettype = p.Type - } - } - - // System call name. - if sysname == "" { - sysname = funct - } - sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`) - sysname = strings.ToLower(sysname) // All libc functions are lowercase. - - cRettype := "" - if rettype == "unsafe.Pointer" { - cRettype = "uintptr_t" - } else if rettype == "uintptr" { - cRettype = "uintptr_t" - } else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil { - cRettype = "uintptr_t" - } else if rettype == "int" { - cRettype = "int" - } else if rettype == "int32" { - cRettype = "int" - } else if rettype == "int64" { - cRettype = "long long" - } else if rettype == "uint32" { - cRettype = "unsigned int" - } else if rettype == "uint64" { - cRettype = "unsigned long long" - } else { - cRettype = "int" - } - if sysname == "exit" { - cRettype = "void" - } - - // Change p.Types to c - var cIn []string - for _, param := range in { - p := parseParam(param) - if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil { - cIn = append(cIn, "uintptr_t") - } else if p.Type == "string" { - cIn = append(cIn, "uintptr_t") - } else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil { - cIn = append(cIn, "uintptr_t", "size_t") - } else if p.Type == "unsafe.Pointer" { - cIn = append(cIn, "uintptr_t") - } else if p.Type == "uintptr" { - cIn = append(cIn, "uintptr_t") - } else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil { - cIn = append(cIn, "uintptr_t") - } else if p.Type == "int" { - cIn = append(cIn, "int") - } else if p.Type == "int32" { - cIn = append(cIn, "int") - } else if p.Type == "int64" { - cIn = append(cIn, "long long") - } else if p.Type == "uint32" { - cIn = append(cIn, "unsigned int") - } else if p.Type == "uint64" { - cIn = append(cIn, "unsigned long long") - } else { - cIn = append(cIn, "int") - } - } - - if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" { - if sysname == "select" { - // select is a keyword of Go. Its name is - // changed to c_select. - cExtern += "#define c_select select\n" - } - // Imports of system calls from libc - cExtern += fmt.Sprintf("%s %s", cRettype, sysname) - cIn := strings.Join(cIn, ", ") - cExtern += fmt.Sprintf("(%s);\n", cIn) - } - - // So file name. - if *aix { - if modname == "" { - modname = "libc.a/shr_64.o" - } else { - fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct) - os.Exit(1) - } - } - - strconvfunc := "C.CString" - - // Go function header. - if outps != "" { - outps = fmt.Sprintf(" (%s)", outps) - } - if text != "" { - text += "\n" - } - - text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps) - - // Prepare arguments to Syscall. - var args []string - n := 0 - argN := 0 - for _, param := range in { - p := parseParam(param) - if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil { - args = append(args, "C.uintptr_t(uintptr(unsafe.Pointer("+p.Name+")))") - } else if p.Type == "string" && errvar != "" { - text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name) - args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n)) - n++ - } else if p.Type == "string" { - fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n") - text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name) - args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n)) - n++ - } else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil { - // Convert slice into pointer, length. - // Have to be careful not to take address of &a[0] if len == 0: - // pass nil in that case. - text += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1]) - text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name) - args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(unsafe.Pointer(_p%d)))", n)) - n++ - text += fmt.Sprintf("\tvar _p%d int\n", n) - text += fmt.Sprintf("\t_p%d = len(%s)\n", n, p.Name) - args = append(args, fmt.Sprintf("C.size_t(_p%d)", n)) - n++ - } else if p.Type == "int64" && endianness != "" { - if endianness == "big-endian" { - args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name)) - } else { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name)) - } - n++ - } else if p.Type == "bool" { - text += fmt.Sprintf("\tvar _p%d uint32\n", n) - text += fmt.Sprintf("\tif %s {\n\t\t_p%d = 1\n\t} else {\n\t\t_p%d = 0\n\t}\n", p.Name, n, n) - args = append(args, fmt.Sprintf("_p%d", n)) - } else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil { - args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name)) - } else if p.Type == "unsafe.Pointer" { - args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name)) - } else if p.Type == "int" { - if (argN == 2) && ((funct == "readlen") || (funct == "writelen")) { - args = append(args, fmt.Sprintf("C.size_t(%s)", p.Name)) - } else if argN == 0 && funct == "fcntl" { - args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name)) - } else if (argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt")) { - args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name)) - } else { - args = append(args, fmt.Sprintf("C.int(%s)", p.Name)) - } - } else if p.Type == "int32" { - args = append(args, fmt.Sprintf("C.int(%s)", p.Name)) - } else if p.Type == "int64" { - args = append(args, fmt.Sprintf("C.longlong(%s)", p.Name)) - } else if p.Type == "uint32" { - args = append(args, fmt.Sprintf("C.uint(%s)", p.Name)) - } else if p.Type == "uint64" { - args = append(args, fmt.Sprintf("C.ulonglong(%s)", p.Name)) - } else if p.Type == "uintptr" { - args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name)) - } else { - args = append(args, fmt.Sprintf("C.int(%s)", p.Name)) - } - argN++ - } - - // Actual call. - arglist := strings.Join(args, ", ") - call := "" - if sysname == "exit" { - if errvar != "" { - call += "er :=" - } else { - call += "" - } - } else if errvar != "" { - call += "r0,er :=" - } else if retvar != "" { - call += "r0,_ :=" - } else { - call += "" - } - if sysname == "select" { - // select is a keyword of Go. Its name is - // changed to c_select. - call += fmt.Sprintf("C.c_%s(%s)", sysname, arglist) - } else { - call += fmt.Sprintf("C.%s(%s)", sysname, arglist) - } - - // Assign return values. - body := "" - for i := 0; i < len(out); i++ { - p := parseParam(out[i]) - reg := "" - if p.Name == "err" { - reg = "e1" - } else { - reg = "r0" - } - if reg != "e1" { - body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg) - } - } - - // verify return - if sysname != "exit" && errvar != "" { - if regexp.MustCompile(`^uintptr`).FindStringSubmatch(cRettype) != nil { - body += "\tif (uintptr(r0) ==^uintptr(0) && er != nil) {\n" - body += fmt.Sprintf("\t\t%s = er\n", errvar) - body += "\t}\n" - } else { - body += "\tif (r0 ==-1 && er != nil) {\n" - body += fmt.Sprintf("\t\t%s = er\n", errvar) - body += "\t}\n" - } - } else if errvar != "" { - body += "\tif (er != nil) {\n" - body += fmt.Sprintf("\t\t%s = er\n", errvar) - body += "\t}\n" - } - - text += fmt.Sprintf("\t%s\n", call) - text += body - - text += "\treturn\n" - text += "}\n" - } - if err := s.Err(); err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - file.Close() - } - imp := "" - if pack != "unix" { - imp = "import \"golang.org/x/sys/unix\"\n" - - } - fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, cExtern, imp, text) -} - -const srcTemplate = `// %s -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s - -package %s - - -%s -*/ -import "C" -import ( - "unsafe" -) - - -%s - -%s -` diff --git a/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go b/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go deleted file mode 100644 index c96009951..000000000 --- a/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go +++ /dev/null @@ -1,614 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -This program reads a file containing function prototypes -(like syscall_aix.go) and generates system call bodies. -The prototypes are marked by lines beginning with "//sys" -and read like func declarations if //sys is replaced by func, but: - * The parameter lists must give a name for each argument. - This includes return parameters. - * The parameter lists must give a type for each argument: - the (x, y, z int) shorthand is not allowed. - * If the return parameter is an error number, it must be named err. - * If go func name needs to be different than its libc name, - * or the function is not in libc, name could be specified - * at the end, after "=" sign, like - //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt - - -This program will generate three files and handle both gc and gccgo implementation: - - zsyscall_aix_ppc64.go: the common part of each implementation (error handler, pointer creation) - - zsyscall_aix_ppc64_gc.go: gc part with //go_cgo_import_dynamic and a call to syscall6 - - zsyscall_aix_ppc64_gccgo.go: gccgo part with C function and conversion to C type. - - The generated code looks like this - -zsyscall_aix_ppc64.go -func asyscall(...) (n int, err error) { - // Pointer Creation - r1, e1 := callasyscall(...) - // Type Conversion - // Error Handler - return -} - -zsyscall_aix_ppc64_gc.go -//go:cgo_import_dynamic libc_asyscall asyscall "libc.a/shr_64.o" -//go:linkname libc_asyscall libc_asyscall -var asyscall syscallFunc - -func callasyscall(...) (r1 uintptr, e1 Errno) { - r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_asyscall)), "nb_args", ... ) - return -} - -zsyscall_aix_ppc64_ggcgo.go - -// int asyscall(...) - -import "C" - -func callasyscall(...) (r1 uintptr, e1 Errno) { - r1 = uintptr(C.asyscall(...)) - e1 = syscall.GetErrno() - return -} -*/ - -package main - -import ( - "bufio" - "flag" - "fmt" - "io/ioutil" - "os" - "regexp" - "strings" -) - -var ( - b32 = flag.Bool("b32", false, "32bit big-endian") - l32 = flag.Bool("l32", false, "32bit little-endian") - aix = flag.Bool("aix", false, "aix") - tags = flag.String("tags", "", "build tags") -) - -// cmdLine returns this programs's commandline arguments -func cmdLine() string { - return "go run mksyscall_aix_ppc64.go " + strings.Join(os.Args[1:], " ") -} - -// buildTags returns build tags -func buildTags() string { - return *tags -} - -// Param is function parameter -type Param struct { - Name string - Type string -} - -// usage prints the program usage -func usage() { - fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc64.go [-b32 | -l32] [-tags x,y] [file ...]\n") - os.Exit(1) -} - -// parseParamList parses parameter list and returns a slice of parameters -func parseParamList(list string) []string { - list = strings.TrimSpace(list) - if list == "" { - return []string{} - } - return regexp.MustCompile(`\s*,\s*`).Split(list, -1) -} - -// parseParam splits a parameter into name and type -func parseParam(p string) Param { - ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p) - if ps == nil { - fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p) - os.Exit(1) - } - return Param{ps[1], ps[2]} -} - -func main() { - flag.Usage = usage - flag.Parse() - if len(flag.Args()) <= 0 { - fmt.Fprintf(os.Stderr, "no files to parse provided\n") - usage() - } - - endianness := "" - if *b32 { - endianness = "big-endian" - } else if *l32 { - endianness = "little-endian" - } - - pack := "" - // GCCGO - textgccgo := "" - cExtern := "/*\n#include \n" - // GC - textgc := "" - dynimports := "" - linknames := "" - var vars []string - // COMMON - textcommon := "" - for _, path := range flag.Args() { - file, err := os.Open(path) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - s := bufio.NewScanner(file) - for s.Scan() { - t := s.Text() - t = strings.TrimSpace(t) - t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `) - if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" { - pack = p[1] - } - nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t) - if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil { - continue - } - - // Line must be of the form - // func Open(path string, mode int, perm int) (fd int, err error) - // Split into name, in params, out params. - f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t) - if f == nil { - fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t) - os.Exit(1) - } - funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6] - - // Split argument lists on comma. - in := parseParamList(inps) - out := parseParamList(outps) - - inps = strings.Join(in, ", ") - outps = strings.Join(out, ", ") - - if sysname == "" { - sysname = funct - } - - onlyCommon := false - if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" { - // This function call another syscall which is already implemented. - // Therefore, the gc and gccgo part must not be generated. - onlyCommon = true - } - - // Try in vain to keep people from editing this file. - // The theory is that they jump into the middle of the file - // without reading the header. - - textcommon += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n" - if !onlyCommon { - textgccgo += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n" - textgc += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n" - } - - // Check if value return, err return available - errvar := "" - rettype := "" - for _, param := range out { - p := parseParam(param) - if p.Type == "error" { - errvar = p.Name - } else { - rettype = p.Type - } - } - - sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`) - sysname = strings.ToLower(sysname) // All libc functions are lowercase. - - // GCCGO Prototype return type - cRettype := "" - if rettype == "unsafe.Pointer" { - cRettype = "uintptr_t" - } else if rettype == "uintptr" { - cRettype = "uintptr_t" - } else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil { - cRettype = "uintptr_t" - } else if rettype == "int" { - cRettype = "int" - } else if rettype == "int32" { - cRettype = "int" - } else if rettype == "int64" { - cRettype = "long long" - } else if rettype == "uint32" { - cRettype = "unsigned int" - } else if rettype == "uint64" { - cRettype = "unsigned long long" - } else { - cRettype = "int" - } - if sysname == "exit" { - cRettype = "void" - } - - // GCCGO Prototype arguments type - var cIn []string - for i, param := range in { - p := parseParam(param) - if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil { - cIn = append(cIn, "uintptr_t") - } else if p.Type == "string" { - cIn = append(cIn, "uintptr_t") - } else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil { - cIn = append(cIn, "uintptr_t", "size_t") - } else if p.Type == "unsafe.Pointer" { - cIn = append(cIn, "uintptr_t") - } else if p.Type == "uintptr" { - cIn = append(cIn, "uintptr_t") - } else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil { - cIn = append(cIn, "uintptr_t") - } else if p.Type == "int" { - if (i == 0 || i == 2) && funct == "fcntl" { - // These fcntl arguments needs to be uintptr to be able to call FcntlInt and FcntlFlock - cIn = append(cIn, "uintptr_t") - } else { - cIn = append(cIn, "int") - } - - } else if p.Type == "int32" { - cIn = append(cIn, "int") - } else if p.Type == "int64" { - cIn = append(cIn, "long long") - } else if p.Type == "uint32" { - cIn = append(cIn, "unsigned int") - } else if p.Type == "uint64" { - cIn = append(cIn, "unsigned long long") - } else { - cIn = append(cIn, "int") - } - } - - if !onlyCommon { - // GCCGO Prototype Generation - // Imports of system calls from libc - if sysname == "select" { - // select is a keyword of Go. Its name is - // changed to c_select. - cExtern += "#define c_select select\n" - } - cExtern += fmt.Sprintf("%s %s", cRettype, sysname) - cIn := strings.Join(cIn, ", ") - cExtern += fmt.Sprintf("(%s);\n", cIn) - } - // GC Library name - if modname == "" { - modname = "libc.a/shr_64.o" - } else { - fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct) - os.Exit(1) - } - sysvarname := fmt.Sprintf("libc_%s", sysname) - - if !onlyCommon { - // GC Runtime import of function to allow cross-platform builds. - dynimports += fmt.Sprintf("//go:cgo_import_dynamic %s %s \"%s\"\n", sysvarname, sysname, modname) - // GC Link symbol to proc address variable. - linknames += fmt.Sprintf("//go:linkname %s %s\n", sysvarname, sysvarname) - // GC Library proc address variable. - vars = append(vars, sysvarname) - } - - strconvfunc := "BytePtrFromString" - strconvtype := "*byte" - - // Go function header. - if outps != "" { - outps = fmt.Sprintf(" (%s)", outps) - } - if textcommon != "" { - textcommon += "\n" - } - - textcommon += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps) - - // Prepare arguments tocall. - var argscommon []string // Arguments in the common part - var argscall []string // Arguments for call prototype - var argsgc []string // Arguments for gc call (with syscall6) - var argsgccgo []string // Arguments for gccgo call (with C.name_of_syscall) - n := 0 - argN := 0 - for _, param := range in { - p := parseParam(param) - if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil { - argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(%s))", p.Name)) - argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name)) - argsgc = append(argsgc, p.Name) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name)) - } else if p.Type == "string" && errvar != "" { - textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype) - textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name) - textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar) - - argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n)) - argscall = append(argscall, fmt.Sprintf("_p%d uintptr ", n)) - argsgc = append(argsgc, fmt.Sprintf("_p%d", n)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n)) - n++ - } else if p.Type == "string" { - fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n") - textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype) - textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name) - textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar) - - argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n)) - argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n)) - argsgc = append(argsgc, fmt.Sprintf("_p%d", n)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n)) - n++ - } else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil { - // Convert slice into pointer, length. - // Have to be careful not to take address of &a[0] if len == 0: - // pass nil in that case. - textcommon += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1]) - textcommon += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name) - argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("len(%s)", p.Name)) - argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n), fmt.Sprintf("_lenp%d int", n)) - argsgc = append(argsgc, fmt.Sprintf("_p%d", n), fmt.Sprintf("uintptr(_lenp%d)", n)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n), fmt.Sprintf("C.size_t(_lenp%d)", n)) - n++ - } else if p.Type == "int64" && endianness != "" { - fmt.Fprintf(os.Stderr, path+":"+funct+" uses int64 with 32 bits mode. Case not yet implemented\n") - } else if p.Type == "bool" { - fmt.Fprintf(os.Stderr, path+":"+funct+" uses bool. Case not yet implemented\n") - } else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil || p.Type == "unsafe.Pointer" { - argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name)) - argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name)) - argsgc = append(argsgc, p.Name) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name)) - } else if p.Type == "int" { - if (argN == 0 || argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt") || (funct == "FcntlFlock")) { - // These fcntl arguments need to be uintptr to be able to call FcntlInt and FcntlFlock - argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name)) - argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name)) - argsgc = append(argsgc, p.Name) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name)) - - } else { - argscommon = append(argscommon, p.Name) - argscall = append(argscall, fmt.Sprintf("%s int", p.Name)) - argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name)) - } - } else if p.Type == "int32" { - argscommon = append(argscommon, p.Name) - argscall = append(argscall, fmt.Sprintf("%s int32", p.Name)) - argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name)) - } else if p.Type == "int64" { - argscommon = append(argscommon, p.Name) - argscall = append(argscall, fmt.Sprintf("%s int64", p.Name)) - argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.longlong(%s)", p.Name)) - } else if p.Type == "uint32" { - argscommon = append(argscommon, p.Name) - argscall = append(argscall, fmt.Sprintf("%s uint32", p.Name)) - argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uint(%s)", p.Name)) - } else if p.Type == "uint64" { - argscommon = append(argscommon, p.Name) - argscall = append(argscall, fmt.Sprintf("%s uint64", p.Name)) - argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.ulonglong(%s)", p.Name)) - } else if p.Type == "uintptr" { - argscommon = append(argscommon, p.Name) - argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name)) - argsgc = append(argsgc, p.Name) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name)) - } else { - argscommon = append(argscommon, fmt.Sprintf("int(%s)", p.Name)) - argscall = append(argscall, fmt.Sprintf("%s int", p.Name)) - argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name)) - argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name)) - } - argN++ - } - nargs := len(argsgc) - - // COMMON function generation - argscommonlist := strings.Join(argscommon, ", ") - callcommon := fmt.Sprintf("call%s(%s)", sysname, argscommonlist) - ret := []string{"_", "_"} - body := "" - doErrno := false - for i := 0; i < len(out); i++ { - p := parseParam(out[i]) - reg := "" - if p.Name == "err" { - reg = "e1" - ret[1] = reg - doErrno = true - } else { - reg = "r0" - ret[0] = reg - } - if p.Type == "bool" { - reg = fmt.Sprintf("%s != 0", reg) - } - if reg != "e1" { - body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg) - } - } - if ret[0] == "_" && ret[1] == "_" { - textcommon += fmt.Sprintf("\t%s\n", callcommon) - } else { - textcommon += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], callcommon) - } - textcommon += body - - if doErrno { - textcommon += "\tif e1 != 0 {\n" - textcommon += "\t\terr = errnoErr(e1)\n" - textcommon += "\t}\n" - } - textcommon += "\treturn\n" - textcommon += "}\n" - - if onlyCommon { - continue - } - - // CALL Prototype - callProto := fmt.Sprintf("func call%s(%s) (r1 uintptr, e1 Errno) {\n", sysname, strings.Join(argscall, ", ")) - - // GC function generation - asm := "syscall6" - if nonblock != nil { - asm = "rawSyscall6" - } - - if len(argsgc) <= 6 { - for len(argsgc) < 6 { - argsgc = append(argsgc, "0") - } - } else { - fmt.Fprintf(os.Stderr, "%s: too many arguments to system call", funct) - os.Exit(1) - } - argsgclist := strings.Join(argsgc, ", ") - callgc := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, argsgclist) - - textgc += callProto - textgc += fmt.Sprintf("\tr1, _, e1 = %s\n", callgc) - textgc += "\treturn\n}\n" - - // GCCGO function generation - argsgccgolist := strings.Join(argsgccgo, ", ") - var callgccgo string - if sysname == "select" { - // select is a keyword of Go. Its name is - // changed to c_select. - callgccgo = fmt.Sprintf("C.c_%s(%s)", sysname, argsgccgolist) - } else { - callgccgo = fmt.Sprintf("C.%s(%s)", sysname, argsgccgolist) - } - textgccgo += callProto - textgccgo += fmt.Sprintf("\tr1 = uintptr(%s)\n", callgccgo) - textgccgo += "\te1 = syscall.GetErrno()\n" - textgccgo += "\treturn\n}\n" - } - if err := s.Err(); err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - file.Close() - } - imp := "" - if pack != "unix" { - imp = "import \"golang.org/x/sys/unix\"\n" - - } - - // Print zsyscall_aix_ppc64.go - err := ioutil.WriteFile("zsyscall_aix_ppc64.go", - []byte(fmt.Sprintf(srcTemplate1, cmdLine(), buildTags(), pack, imp, textcommon)), - 0644) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - - // Print zsyscall_aix_ppc64_gc.go - vardecls := "\t" + strings.Join(vars, ",\n\t") - vardecls += " syscallFunc" - err = ioutil.WriteFile("zsyscall_aix_ppc64_gc.go", - []byte(fmt.Sprintf(srcTemplate2, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, textgc)), - 0644) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - - // Print zsyscall_aix_ppc64_gccgo.go - err = ioutil.WriteFile("zsyscall_aix_ppc64_gccgo.go", - []byte(fmt.Sprintf(srcTemplate3, cmdLine(), buildTags(), pack, cExtern, imp, textgccgo)), - 0644) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } -} - -const srcTemplate1 = `// %s -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s - -package %s - -import ( - "unsafe" -) - - -%s - -%s -` -const srcTemplate2 = `// %s -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s -// +build !gccgo - -package %s - -import ( - "unsafe" -) -%s -%s -%s -type syscallFunc uintptr - -var ( -%s -) - -// Implemented in runtime/syscall_aix.go. -func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) -func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) - -%s -` -const srcTemplate3 = `// %s -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s -// +build gccgo - -package %s - -%s -*/ -import "C" -import ( - "syscall" -) - - -%s - -%s -` diff --git a/vendor/golang.org/x/sys/unix/mksyscall_solaris.go b/vendor/golang.org/x/sys/unix/mksyscall_solaris.go deleted file mode 100644 index 3d864738b..000000000 --- a/vendor/golang.org/x/sys/unix/mksyscall_solaris.go +++ /dev/null @@ -1,335 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* - This program reads a file containing function prototypes - (like syscall_solaris.go) and generates system call bodies. - The prototypes are marked by lines beginning with "//sys" - and read like func declarations if //sys is replaced by func, but: - * The parameter lists must give a name for each argument. - This includes return parameters. - * The parameter lists must give a type for each argument: - the (x, y, z int) shorthand is not allowed. - * If the return parameter is an error number, it must be named err. - * If go func name needs to be different than its libc name, - * or the function is not in libc, name could be specified - * at the end, after "=" sign, like - //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt -*/ - -package main - -import ( - "bufio" - "flag" - "fmt" - "os" - "regexp" - "strings" -) - -var ( - b32 = flag.Bool("b32", false, "32bit big-endian") - l32 = flag.Bool("l32", false, "32bit little-endian") - tags = flag.String("tags", "", "build tags") -) - -// cmdLine returns this programs's commandline arguments -func cmdLine() string { - return "go run mksyscall_solaris.go " + strings.Join(os.Args[1:], " ") -} - -// buildTags returns build tags -func buildTags() string { - return *tags -} - -// Param is function parameter -type Param struct { - Name string - Type string -} - -// usage prints the program usage -func usage() { - fmt.Fprintf(os.Stderr, "usage: go run mksyscall_solaris.go [-b32 | -l32] [-tags x,y] [file ...]\n") - os.Exit(1) -} - -// parseParamList parses parameter list and returns a slice of parameters -func parseParamList(list string) []string { - list = strings.TrimSpace(list) - if list == "" { - return []string{} - } - return regexp.MustCompile(`\s*,\s*`).Split(list, -1) -} - -// parseParam splits a parameter into name and type -func parseParam(p string) Param { - ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p) - if ps == nil { - fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p) - os.Exit(1) - } - return Param{ps[1], ps[2]} -} - -func main() { - flag.Usage = usage - flag.Parse() - if len(flag.Args()) <= 0 { - fmt.Fprintf(os.Stderr, "no files to parse provided\n") - usage() - } - - endianness := "" - if *b32 { - endianness = "big-endian" - } else if *l32 { - endianness = "little-endian" - } - - pack := "" - text := "" - dynimports := "" - linknames := "" - var vars []string - for _, path := range flag.Args() { - file, err := os.Open(path) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - s := bufio.NewScanner(file) - for s.Scan() { - t := s.Text() - t = strings.TrimSpace(t) - t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `) - if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" { - pack = p[1] - } - nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t) - if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil { - continue - } - - // Line must be of the form - // func Open(path string, mode int, perm int) (fd int, err error) - // Split into name, in params, out params. - f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t) - if f == nil { - fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t) - os.Exit(1) - } - funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6] - - // Split argument lists on comma. - in := parseParamList(inps) - out := parseParamList(outps) - - inps = strings.Join(in, ", ") - outps = strings.Join(out, ", ") - - // Try in vain to keep people from editing this file. - // The theory is that they jump into the middle of the file - // without reading the header. - text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n" - - // So file name. - if modname == "" { - modname = "libc" - } - - // System call name. - if sysname == "" { - sysname = funct - } - - // System call pointer variable name. - sysvarname := fmt.Sprintf("proc%s", sysname) - - strconvfunc := "BytePtrFromString" - strconvtype := "*byte" - - sysname = strings.ToLower(sysname) // All libc functions are lowercase. - - // Runtime import of function to allow cross-platform builds. - dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname) - // Link symbol to proc address variable. - linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname) - // Library proc address variable. - vars = append(vars, sysvarname) - - // Go function header. - outlist := strings.Join(out, ", ") - if outlist != "" { - outlist = fmt.Sprintf(" (%s)", outlist) - } - if text != "" { - text += "\n" - } - text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outlist) - - // Check if err return available - errvar := "" - for _, param := range out { - p := parseParam(param) - if p.Type == "error" { - errvar = p.Name - continue - } - } - - // Prepare arguments to Syscall. - var args []string - n := 0 - for _, param := range in { - p := parseParam(param) - if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil { - args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))") - } else if p.Type == "string" && errvar != "" { - text += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype) - text += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name) - text += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar) - args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n)) - n++ - } else if p.Type == "string" { - fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n") - text += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype) - text += fmt.Sprintf("\t_p%d, _ = %s(%s)\n", n, strconvfunc, p.Name) - args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n)) - n++ - } else if s := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); s != nil { - // Convert slice into pointer, length. - // Have to be careful not to take address of &a[0] if len == 0: - // pass nil in that case. - text += fmt.Sprintf("\tvar _p%d *%s\n", n, s[1]) - text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name) - args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("uintptr(len(%s))", p.Name)) - n++ - } else if p.Type == "int64" && endianness != "" { - if endianness == "big-endian" { - args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name)) - } else { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name)) - } - } else if p.Type == "bool" { - text += fmt.Sprintf("\tvar _p%d uint32\n", n) - text += fmt.Sprintf("\tif %s {\n\t\t_p%d = 1\n\t} else {\n\t\t_p%d = 0\n\t}\n", p.Name, n, n) - args = append(args, fmt.Sprintf("uintptr(_p%d)", n)) - n++ - } else { - args = append(args, fmt.Sprintf("uintptr(%s)", p.Name)) - } - } - nargs := len(args) - - // Determine which form to use; pad args with zeros. - asm := "sysvicall6" - if nonblock != nil { - asm = "rawSysvicall6" - } - if len(args) <= 6 { - for len(args) < 6 { - args = append(args, "0") - } - } else { - fmt.Fprintf(os.Stderr, "%s: too many arguments to system call\n", path) - os.Exit(1) - } - - // Actual call. - arglist := strings.Join(args, ", ") - call := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, arglist) - - // Assign return values. - body := "" - ret := []string{"_", "_", "_"} - doErrno := false - for i := 0; i < len(out); i++ { - p := parseParam(out[i]) - reg := "" - if p.Name == "err" { - reg = "e1" - ret[2] = reg - doErrno = true - } else { - reg = fmt.Sprintf("r%d", i) - ret[i] = reg - } - if p.Type == "bool" { - reg = fmt.Sprintf("%d != 0", reg) - } - if p.Type == "int64" && endianness != "" { - // 64-bit number in r1:r0 or r0:r1. - if i+2 > len(out) { - fmt.Fprintf(os.Stderr, "%s: not enough registers for int64 return\n", path) - os.Exit(1) - } - if endianness == "big-endian" { - reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i, i+1) - } else { - reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i+1, i) - } - ret[i] = fmt.Sprintf("r%d", i) - ret[i+1] = fmt.Sprintf("r%d", i+1) - } - if reg != "e1" { - body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg) - } - } - if ret[0] == "_" && ret[1] == "_" && ret[2] == "_" { - text += fmt.Sprintf("\t%s\n", call) - } else { - text += fmt.Sprintf("\t%s, %s, %s := %s\n", ret[0], ret[1], ret[2], call) - } - text += body - - if doErrno { - text += "\tif e1 != 0 {\n" - text += "\t\terr = e1\n" - text += "\t}\n" - } - text += "\treturn\n" - text += "}\n" - } - if err := s.Err(); err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - file.Close() - } - imp := "" - if pack != "unix" { - imp = "import \"golang.org/x/sys/unix\"\n" - - } - vardecls := "\t" + strings.Join(vars, ",\n\t") - vardecls += " syscallFunc" - fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, text) -} - -const srcTemplate = `// %s -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s - -package %s - -import ( - "syscall" - "unsafe" -) -%s -%s -%s -var ( -%s -) - -%s -` diff --git a/vendor/golang.org/x/sys/unix/mksysctl_openbsd.go b/vendor/golang.org/x/sys/unix/mksysctl_openbsd.go deleted file mode 100644 index b6b409909..000000000 --- a/vendor/golang.org/x/sys/unix/mksysctl_openbsd.go +++ /dev/null @@ -1,355 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Parse the header files for OpenBSD and generate a Go usable sysctl MIB. -// -// Build a MIB with each entry being an array containing the level, type and -// a hash that will contain additional entries if the current entry is a node. -// We then walk this MIB and create a flattened sysctl name to OID hash. - -package main - -import ( - "bufio" - "fmt" - "os" - "path/filepath" - "regexp" - "sort" - "strings" -) - -var ( - goos, goarch string -) - -// cmdLine returns this programs's commandline arguments. -func cmdLine() string { - return "go run mksysctl_openbsd.go " + strings.Join(os.Args[1:], " ") -} - -// buildTags returns build tags. -func buildTags() string { - return fmt.Sprintf("%s,%s", goarch, goos) -} - -// reMatch performs regular expression match and stores the substring slice to value pointed by m. -func reMatch(re *regexp.Regexp, str string, m *[]string) bool { - *m = re.FindStringSubmatch(str) - if *m != nil { - return true - } - return false -} - -type nodeElement struct { - n int - t string - pE *map[string]nodeElement -} - -var ( - debugEnabled bool - mib map[string]nodeElement - node *map[string]nodeElement - nodeMap map[string]string - sysCtl []string -) - -var ( - ctlNames1RE = regexp.MustCompile(`^#define\s+(CTL_NAMES)\s+{`) - ctlNames2RE = regexp.MustCompile(`^#define\s+(CTL_(.*)_NAMES)\s+{`) - ctlNames3RE = regexp.MustCompile(`^#define\s+((.*)CTL_NAMES)\s+{`) - netInetRE = regexp.MustCompile(`^netinet/`) - netInet6RE = regexp.MustCompile(`^netinet6/`) - netRE = regexp.MustCompile(`^net/`) - bracesRE = regexp.MustCompile(`{.*}`) - ctlTypeRE = regexp.MustCompile(`{\s+"(\w+)",\s+(CTLTYPE_[A-Z]+)\s+}`) - fsNetKernRE = regexp.MustCompile(`^(fs|net|kern)_`) -) - -func debug(s string) { - if debugEnabled { - fmt.Fprintln(os.Stderr, s) - } -} - -// Walk the MIB and build a sysctl name to OID mapping. -func buildSysctl(pNode *map[string]nodeElement, name string, oid []int) { - lNode := pNode // local copy of pointer to node - var keys []string - for k := range *lNode { - keys = append(keys, k) - } - sort.Strings(keys) - - for _, key := range keys { - nodename := name - if name != "" { - nodename += "." - } - nodename += key - - nodeoid := append(oid, (*pNode)[key].n) - - if (*pNode)[key].t == `CTLTYPE_NODE` { - if _, ok := nodeMap[nodename]; ok { - lNode = &mib - ctlName := nodeMap[nodename] - for _, part := range strings.Split(ctlName, ".") { - lNode = ((*lNode)[part]).pE - } - } else { - lNode = (*pNode)[key].pE - } - buildSysctl(lNode, nodename, nodeoid) - } else if (*pNode)[key].t != "" { - oidStr := []string{} - for j := range nodeoid { - oidStr = append(oidStr, fmt.Sprintf("%d", nodeoid[j])) - } - text := "\t{ \"" + nodename + "\", []_C_int{ " + strings.Join(oidStr, ", ") + " } }, \n" - sysCtl = append(sysCtl, text) - } - } -} - -func main() { - // Get the OS (using GOOS_TARGET if it exist) - goos = os.Getenv("GOOS_TARGET") - if goos == "" { - goos = os.Getenv("GOOS") - } - // Get the architecture (using GOARCH_TARGET if it exists) - goarch = os.Getenv("GOARCH_TARGET") - if goarch == "" { - goarch = os.Getenv("GOARCH") - } - // Check if GOOS and GOARCH environment variables are defined - if goarch == "" || goos == "" { - fmt.Fprintf(os.Stderr, "GOARCH or GOOS not defined in environment\n") - os.Exit(1) - } - - mib = make(map[string]nodeElement) - headers := [...]string{ - `sys/sysctl.h`, - `sys/socket.h`, - `sys/tty.h`, - `sys/malloc.h`, - `sys/mount.h`, - `sys/namei.h`, - `sys/sem.h`, - `sys/shm.h`, - `sys/vmmeter.h`, - `uvm/uvmexp.h`, - `uvm/uvm_param.h`, - `uvm/uvm_swap_encrypt.h`, - `ddb/db_var.h`, - `net/if.h`, - `net/if_pfsync.h`, - `net/pipex.h`, - `netinet/in.h`, - `netinet/icmp_var.h`, - `netinet/igmp_var.h`, - `netinet/ip_ah.h`, - `netinet/ip_carp.h`, - `netinet/ip_divert.h`, - `netinet/ip_esp.h`, - `netinet/ip_ether.h`, - `netinet/ip_gre.h`, - `netinet/ip_ipcomp.h`, - `netinet/ip_ipip.h`, - `netinet/pim_var.h`, - `netinet/tcp_var.h`, - `netinet/udp_var.h`, - `netinet6/in6.h`, - `netinet6/ip6_divert.h`, - `netinet6/pim6_var.h`, - `netinet/icmp6.h`, - `netmpls/mpls.h`, - } - - ctls := [...]string{ - `kern`, - `vm`, - `fs`, - `net`, - //debug /* Special handling required */ - `hw`, - //machdep /* Arch specific */ - `user`, - `ddb`, - //vfs /* Special handling required */ - `fs.posix`, - `kern.forkstat`, - `kern.intrcnt`, - `kern.malloc`, - `kern.nchstats`, - `kern.seminfo`, - `kern.shminfo`, - `kern.timecounter`, - `kern.tty`, - `kern.watchdog`, - `net.bpf`, - `net.ifq`, - `net.inet`, - `net.inet.ah`, - `net.inet.carp`, - `net.inet.divert`, - `net.inet.esp`, - `net.inet.etherip`, - `net.inet.gre`, - `net.inet.icmp`, - `net.inet.igmp`, - `net.inet.ip`, - `net.inet.ip.ifq`, - `net.inet.ipcomp`, - `net.inet.ipip`, - `net.inet.mobileip`, - `net.inet.pfsync`, - `net.inet.pim`, - `net.inet.tcp`, - `net.inet.udp`, - `net.inet6`, - `net.inet6.divert`, - `net.inet6.ip6`, - `net.inet6.icmp6`, - `net.inet6.pim6`, - `net.inet6.tcp6`, - `net.inet6.udp6`, - `net.mpls`, - `net.mpls.ifq`, - `net.key`, - `net.pflow`, - `net.pfsync`, - `net.pipex`, - `net.rt`, - `vm.swapencrypt`, - //vfsgenctl /* Special handling required */ - } - - // Node name "fixups" - ctlMap := map[string]string{ - "ipproto": "net.inet", - "net.inet.ipproto": "net.inet", - "net.inet6.ipv6proto": "net.inet6", - "net.inet6.ipv6": "net.inet6.ip6", - "net.inet.icmpv6": "net.inet6.icmp6", - "net.inet6.divert6": "net.inet6.divert", - "net.inet6.tcp6": "net.inet.tcp", - "net.inet6.udp6": "net.inet.udp", - "mpls": "net.mpls", - "swpenc": "vm.swapencrypt", - } - - // Node mappings - nodeMap = map[string]string{ - "net.inet.ip.ifq": "net.ifq", - "net.inet.pfsync": "net.pfsync", - "net.mpls.ifq": "net.ifq", - } - - mCtls := make(map[string]bool) - for _, ctl := range ctls { - mCtls[ctl] = true - } - - for _, header := range headers { - debug("Processing " + header) - file, err := os.Open(filepath.Join("/usr/include", header)) - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - os.Exit(1) - } - s := bufio.NewScanner(file) - for s.Scan() { - var sub []string - if reMatch(ctlNames1RE, s.Text(), &sub) || - reMatch(ctlNames2RE, s.Text(), &sub) || - reMatch(ctlNames3RE, s.Text(), &sub) { - if sub[1] == `CTL_NAMES` { - // Top level. - node = &mib - } else { - // Node. - nodename := strings.ToLower(sub[2]) - ctlName := "" - if reMatch(netInetRE, header, &sub) { - ctlName = "net.inet." + nodename - } else if reMatch(netInet6RE, header, &sub) { - ctlName = "net.inet6." + nodename - } else if reMatch(netRE, header, &sub) { - ctlName = "net." + nodename - } else { - ctlName = nodename - ctlName = fsNetKernRE.ReplaceAllString(ctlName, `$1.`) - } - - if val, ok := ctlMap[ctlName]; ok { - ctlName = val - } - if _, ok := mCtls[ctlName]; !ok { - debug("Ignoring " + ctlName + "...") - continue - } - - // Walk down from the top of the MIB. - node = &mib - for _, part := range strings.Split(ctlName, ".") { - if _, ok := (*node)[part]; !ok { - debug("Missing node " + part) - (*node)[part] = nodeElement{n: 0, t: "", pE: &map[string]nodeElement{}} - } - node = (*node)[part].pE - } - } - - // Populate current node with entries. - i := -1 - for !strings.HasPrefix(s.Text(), "}") { - s.Scan() - if reMatch(bracesRE, s.Text(), &sub) { - i++ - } - if !reMatch(ctlTypeRE, s.Text(), &sub) { - continue - } - (*node)[sub[1]] = nodeElement{n: i, t: sub[2], pE: &map[string]nodeElement{}} - } - } - } - err = s.Err() - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - os.Exit(1) - } - file.Close() - } - buildSysctl(&mib, "", []int{}) - - sort.Strings(sysCtl) - text := strings.Join(sysCtl, "") - - fmt.Printf(srcTemplate, cmdLine(), buildTags(), text) -} - -const srcTemplate = `// %s -// Code generated by the command above; DO NOT EDIT. - -// +build %s - -package unix - -type mibentry struct { - ctlname string - ctloid []_C_int -} - -var sysctlMib = []mibentry { -%s -} -` diff --git a/vendor/golang.org/x/sys/unix/mksysnum.go b/vendor/golang.org/x/sys/unix/mksysnum.go deleted file mode 100644 index baa6ecd85..000000000 --- a/vendor/golang.org/x/sys/unix/mksysnum.go +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright 2018 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Generate system call table for DragonFly, NetBSD, -// FreeBSD, OpenBSD or Darwin from master list -// (for example, /usr/src/sys/kern/syscalls.master or -// sys/syscall.h). -package main - -import ( - "bufio" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "regexp" - "strings" -) - -var ( - goos, goarch string -) - -// cmdLine returns this programs's commandline arguments -func cmdLine() string { - return "go run mksysnum.go " + strings.Join(os.Args[1:], " ") -} - -// buildTags returns build tags -func buildTags() string { - return fmt.Sprintf("%s,%s", goarch, goos) -} - -func checkErr(err error) { - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - os.Exit(1) - } -} - -// source string and substring slice for regexp -type re struct { - str string // source string - sub []string // matched sub-string -} - -// Match performs regular expression match -func (r *re) Match(exp string) bool { - r.sub = regexp.MustCompile(exp).FindStringSubmatch(r.str) - if r.sub != nil { - return true - } - return false -} - -// fetchFile fetches a text file from URL -func fetchFile(URL string) io.Reader { - resp, err := http.Get(URL) - checkErr(err) - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - checkErr(err) - return strings.NewReader(string(body)) -} - -// readFile reads a text file from path -func readFile(path string) io.Reader { - file, err := os.Open(os.Args[1]) - checkErr(err) - return file -} - -func format(name, num, proto string) string { - name = strings.ToUpper(name) - // There are multiple entries for enosys and nosys, so comment them out. - nm := re{str: name} - if nm.Match(`^SYS_E?NOSYS$`) { - name = fmt.Sprintf("// %s", name) - } - if name == `SYS_SYS_EXIT` { - name = `SYS_EXIT` - } - return fmt.Sprintf(" %s = %s; // %s\n", name, num, proto) -} - -func main() { - // Get the OS (using GOOS_TARGET if it exist) - goos = os.Getenv("GOOS_TARGET") - if goos == "" { - goos = os.Getenv("GOOS") - } - // Get the architecture (using GOARCH_TARGET if it exists) - goarch = os.Getenv("GOARCH_TARGET") - if goarch == "" { - goarch = os.Getenv("GOARCH") - } - // Check if GOOS and GOARCH environment variables are defined - if goarch == "" || goos == "" { - fmt.Fprintf(os.Stderr, "GOARCH or GOOS not defined in environment\n") - os.Exit(1) - } - - file := strings.TrimSpace(os.Args[1]) - var syscalls io.Reader - if strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "http://") { - // Download syscalls.master file - syscalls = fetchFile(file) - } else { - syscalls = readFile(file) - } - - var text, line string - s := bufio.NewScanner(syscalls) - for s.Scan() { - t := re{str: line} - if t.Match(`^(.*)\\$`) { - // Handle continuation - line = t.sub[1] - line += strings.TrimLeft(s.Text(), " \t") - } else { - // New line - line = s.Text() - } - t = re{str: line} - if t.Match(`\\$`) { - continue - } - t = re{str: line} - - switch goos { - case "dragonfly": - if t.Match(`^([0-9]+)\s+STD\s+({ \S+\s+(\w+).*)$`) { - num, proto := t.sub[1], t.sub[2] - name := fmt.Sprintf("SYS_%s", t.sub[3]) - text += format(name, num, proto) - } - case "freebsd": - if t.Match(`^([0-9]+)\s+\S+\s+(?:(?:NO)?STD|COMPAT10)\s+({ \S+\s+(\w+).*)$`) { - num, proto := t.sub[1], t.sub[2] - name := fmt.Sprintf("SYS_%s", t.sub[3]) - text += format(name, num, proto) - } - case "openbsd": - if t.Match(`^([0-9]+)\s+STD\s+(NOLOCK\s+)?({ \S+\s+\*?(\w+).*)$`) { - num, proto, name := t.sub[1], t.sub[3], t.sub[4] - text += format(name, num, proto) - } - case "netbsd": - if t.Match(`^([0-9]+)\s+((STD)|(NOERR))\s+(RUMP\s+)?({\s+\S+\s*\*?\s*\|(\S+)\|(\S*)\|(\w+).*\s+})(\s+(\S+))?$`) { - num, proto, compat := t.sub[1], t.sub[6], t.sub[8] - name := t.sub[7] + "_" + t.sub[9] - if t.sub[11] != "" { - name = t.sub[7] + "_" + t.sub[11] - } - name = strings.ToUpper(name) - if compat == "" || compat == "13" || compat == "30" || compat == "50" { - text += fmt.Sprintf(" %s = %s; // %s\n", name, num, proto) - } - } - case "darwin": - if t.Match(`^#define\s+SYS_(\w+)\s+([0-9]+)`) { - name, num := t.sub[1], t.sub[2] - name = strings.ToUpper(name) - text += fmt.Sprintf(" SYS_%s = %s;\n", name, num) - } - default: - fmt.Fprintf(os.Stderr, "unrecognized GOOS=%s\n", goos) - os.Exit(1) - - } - } - err := s.Err() - checkErr(err) - - fmt.Printf(template, cmdLine(), buildTags(), text) -} - -const template = `// %s -// Code generated by the command above; see README.md. DO NOT EDIT. - -// +build %s - -package unix - -const( -%s)` diff --git a/vendor/golang.org/x/sys/unix/types_aix.go b/vendor/golang.org/x/sys/unix/types_aix.go deleted file mode 100644 index 40d2beede..000000000 --- a/vendor/golang.org/x/sys/unix/types_aix.go +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright 2018 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore -// +build aix - -/* -Input to cgo -godefs. See also mkerrors.sh and mkall.sh -*/ - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package unix - -/* -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - - -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -union sockaddr_all { - struct sockaddr s1; // this one gets used for fields - struct sockaddr_in s2; // these pad it out - struct sockaddr_in6 s3; - struct sockaddr_un s4; - struct sockaddr_dl s5; -}; - -struct sockaddr_any { - struct sockaddr addr; - char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; -}; - -*/ -import "C" - -// Machine characteristics - -const ( - SizeofPtr = C.sizeofPtr - SizeofShort = C.sizeof_short - SizeofInt = C.sizeof_int - SizeofLong = C.sizeof_long - SizeofLongLong = C.sizeof_longlong - PathMax = C.PATH_MAX -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong -) - -type off64 C.off64_t -type off C.off_t -type Mode_t C.mode_t - -// Time - -type Timespec C.struct_timespec - -type Timeval C.struct_timeval - -type Timeval32 C.struct_timeval32 - -type Timex C.struct_timex - -type Time_t C.time_t - -type Tms C.struct_tms - -type Utimbuf C.struct_utimbuf - -type Timezone C.struct_timezone - -// Processes - -type Rusage C.struct_rusage - -type Rlimit C.struct_rlimit64 - -type Pid_t C.pid_t - -type _Gid_t C.gid_t - -type dev_t C.dev_t - -// Files - -type Stat_t C.struct_stat - -type StatxTimestamp C.struct_statx_timestamp - -type Statx_t C.struct_statx - -type Dirent C.struct_dirent - -// Sockets - -type RawSockaddrInet4 C.struct_sockaddr_in - -type RawSockaddrInet6 C.struct_sockaddr_in6 - -type RawSockaddrUnix C.struct_sockaddr_un - -type RawSockaddrDatalink C.struct_sockaddr_dl - -type RawSockaddr C.struct_sockaddr - -type RawSockaddrAny C.struct_sockaddr_any - -type _Socklen C.socklen_t - -type Cmsghdr C.struct_cmsghdr - -type ICMPv6Filter C.struct_icmp6_filter - -type Iovec C.struct_iovec - -type IPMreq C.struct_ip_mreq - -type IPv6Mreq C.struct_ipv6_mreq - -type IPv6MTUInfo C.struct_ip6_mtuinfo - -type Linger C.struct_linger - -type Msghdr C.struct_msghdr - -const ( - SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in - SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 - SizeofSockaddrAny = C.sizeof_struct_sockaddr_any - SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un - SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl - SizeofLinger = C.sizeof_struct_linger - SizeofIPMreq = C.sizeof_struct_ip_mreq - SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq - SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo - SizeofMsghdr = C.sizeof_struct_msghdr - SizeofCmsghdr = C.sizeof_struct_cmsghdr - SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter -) - -// Routing and interface messages - -const ( - SizeofIfMsghdr = C.sizeof_struct_if_msghdr -) - -type IfMsgHdr C.struct_if_msghdr - -// Misc - -type FdSet C.fd_set - -type Utsname C.struct_utsname - -type Ustat_t C.struct_ustat - -type Sigset_t C.sigset_t - -const ( - AT_FDCWD = C.AT_FDCWD - AT_REMOVEDIR = C.AT_REMOVEDIR - AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW -) - -// Terminal handling - -type Termios C.struct_termios - -type Termio C.struct_termio - -type Winsize C.struct_winsize - -//poll - -type PollFd struct { - Fd int32 - Events uint16 - Revents uint16 -} - -const ( - POLLERR = C.POLLERR - POLLHUP = C.POLLHUP - POLLIN = C.POLLIN - POLLNVAL = C.POLLNVAL - POLLOUT = C.POLLOUT - POLLPRI = C.POLLPRI - POLLRDBAND = C.POLLRDBAND - POLLRDNORM = C.POLLRDNORM - POLLWRBAND = C.POLLWRBAND - POLLWRNORM = C.POLLWRNORM -) - -//flock_t - -type Flock_t C.struct_flock64 - -// Statfs - -type Fsid_t C.struct_fsid_t -type Fsid64_t C.struct_fsid64_t - -type Statfs_t C.struct_statfs - -const RNDGETENTCNT = 0x80045200 diff --git a/vendor/golang.org/x/sys/unix/types_darwin.go b/vendor/golang.org/x/sys/unix/types_darwin.go deleted file mode 100644 index 155c2e692..000000000 --- a/vendor/golang.org/x/sys/unix/types_darwin.go +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -Input to cgo -godefs. See README.md -*/ - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package unix - -/* -#define __DARWIN_UNIX03 0 -#define KERNEL -#define _DARWIN_USE_64_BIT_INODE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -union sockaddr_all { - struct sockaddr s1; // this one gets used for fields - struct sockaddr_in s2; // these pad it out - struct sockaddr_in6 s3; - struct sockaddr_un s4; - struct sockaddr_dl s5; -}; - -struct sockaddr_any { - struct sockaddr addr; - char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; -}; - -*/ -import "C" - -// Machine characteristics - -const ( - SizeofPtr = C.sizeofPtr - SizeofShort = C.sizeof_short - SizeofInt = C.sizeof_int - SizeofLong = C.sizeof_long - SizeofLongLong = C.sizeof_longlong -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong -) - -// Time - -type Timespec C.struct_timespec - -type Timeval C.struct_timeval - -type Timeval32 C.struct_timeval32 - -// Processes - -type Rusage C.struct_rusage - -type Rlimit C.struct_rlimit - -type _Gid_t C.gid_t - -// Files - -type Stat_t C.struct_stat64 - -type Statfs_t C.struct_statfs64 - -type Flock_t C.struct_flock - -type Fstore_t C.struct_fstore - -type Radvisory_t C.struct_radvisory - -type Fbootstraptransfer_t C.struct_fbootstraptransfer - -type Log2phys_t C.struct_log2phys - -type Fsid C.struct_fsid - -type Dirent C.struct_dirent - -// Sockets - -type RawSockaddrInet4 C.struct_sockaddr_in - -type RawSockaddrInet6 C.struct_sockaddr_in6 - -type RawSockaddrUnix C.struct_sockaddr_un - -type RawSockaddrDatalink C.struct_sockaddr_dl - -type RawSockaddr C.struct_sockaddr - -type RawSockaddrAny C.struct_sockaddr_any - -type _Socklen C.socklen_t - -type Linger C.struct_linger - -type Iovec C.struct_iovec - -type IPMreq C.struct_ip_mreq - -type IPv6Mreq C.struct_ipv6_mreq - -type Msghdr C.struct_msghdr - -type Cmsghdr C.struct_cmsghdr - -type Inet4Pktinfo C.struct_in_pktinfo - -type Inet6Pktinfo C.struct_in6_pktinfo - -type IPv6MTUInfo C.struct_ip6_mtuinfo - -type ICMPv6Filter C.struct_icmp6_filter - -const ( - SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in - SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 - SizeofSockaddrAny = C.sizeof_struct_sockaddr_any - SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un - SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl - SizeofLinger = C.sizeof_struct_linger - SizeofIPMreq = C.sizeof_struct_ip_mreq - SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq - SizeofMsghdr = C.sizeof_struct_msghdr - SizeofCmsghdr = C.sizeof_struct_cmsghdr - SizeofInet4Pktinfo = C.sizeof_struct_in_pktinfo - SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo - SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo - SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter -) - -// Ptrace requests - -const ( - PTRACE_TRACEME = C.PT_TRACE_ME - PTRACE_CONT = C.PT_CONTINUE - PTRACE_KILL = C.PT_KILL -) - -// Events (kqueue, kevent) - -type Kevent_t C.struct_kevent - -// Select - -type FdSet C.fd_set - -// Routing and interface messages - -const ( - SizeofIfMsghdr = C.sizeof_struct_if_msghdr - SizeofIfData = C.sizeof_struct_if_data - SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr - SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr - SizeofIfmaMsghdr2 = C.sizeof_struct_ifma_msghdr2 - SizeofRtMsghdr = C.sizeof_struct_rt_msghdr - SizeofRtMetrics = C.sizeof_struct_rt_metrics -) - -type IfMsghdr C.struct_if_msghdr - -type IfData C.struct_if_data - -type IfaMsghdr C.struct_ifa_msghdr - -type IfmaMsghdr C.struct_ifma_msghdr - -type IfmaMsghdr2 C.struct_ifma_msghdr2 - -type RtMsghdr C.struct_rt_msghdr - -type RtMetrics C.struct_rt_metrics - -// Berkeley packet filter - -const ( - SizeofBpfVersion = C.sizeof_struct_bpf_version - SizeofBpfStat = C.sizeof_struct_bpf_stat - SizeofBpfProgram = C.sizeof_struct_bpf_program - SizeofBpfInsn = C.sizeof_struct_bpf_insn - SizeofBpfHdr = C.sizeof_struct_bpf_hdr -) - -type BpfVersion C.struct_bpf_version - -type BpfStat C.struct_bpf_stat - -type BpfProgram C.struct_bpf_program - -type BpfInsn C.struct_bpf_insn - -type BpfHdr C.struct_bpf_hdr - -// Terminal handling - -type Termios C.struct_termios - -type Winsize C.struct_winsize - -// fchmodat-like syscalls. - -const ( - AT_FDCWD = C.AT_FDCWD - AT_REMOVEDIR = C.AT_REMOVEDIR - AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW - AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW -) - -// poll - -type PollFd C.struct_pollfd - -const ( - POLLERR = C.POLLERR - POLLHUP = C.POLLHUP - POLLIN = C.POLLIN - POLLNVAL = C.POLLNVAL - POLLOUT = C.POLLOUT - POLLPRI = C.POLLPRI - POLLRDBAND = C.POLLRDBAND - POLLRDNORM = C.POLLRDNORM - POLLWRBAND = C.POLLWRBAND - POLLWRNORM = C.POLLWRNORM -) - -// uname - -type Utsname C.struct_utsname - -// Clockinfo - -const SizeofClockinfo = C.sizeof_struct_clockinfo - -type Clockinfo C.struct_clockinfo diff --git a/vendor/golang.org/x/sys/unix/types_dragonfly.go b/vendor/golang.org/x/sys/unix/types_dragonfly.go deleted file mode 100644 index 3365dd79d..000000000 --- a/vendor/golang.org/x/sys/unix/types_dragonfly.go +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -Input to cgo -godefs. See README.md -*/ - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package unix - -/* -#define KERNEL -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -union sockaddr_all { - struct sockaddr s1; // this one gets used for fields - struct sockaddr_in s2; // these pad it out - struct sockaddr_in6 s3; - struct sockaddr_un s4; - struct sockaddr_dl s5; -}; - -struct sockaddr_any { - struct sockaddr addr; - char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; -}; - -*/ -import "C" - -// Machine characteristics - -const ( - SizeofPtr = C.sizeofPtr - SizeofShort = C.sizeof_short - SizeofInt = C.sizeof_int - SizeofLong = C.sizeof_long - SizeofLongLong = C.sizeof_longlong -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong -) - -// Time - -type Timespec C.struct_timespec - -type Timeval C.struct_timeval - -// Processes - -type Rusage C.struct_rusage - -type Rlimit C.struct_rlimit - -type _Gid_t C.gid_t - -// Files - -type Stat_t C.struct_stat - -type Statfs_t C.struct_statfs - -type Flock_t C.struct_flock - -type Dirent C.struct_dirent - -type Fsid C.struct_fsid - -// File system limits - -const ( - PathMax = C.PATH_MAX -) - -// Sockets - -type RawSockaddrInet4 C.struct_sockaddr_in - -type RawSockaddrInet6 C.struct_sockaddr_in6 - -type RawSockaddrUnix C.struct_sockaddr_un - -type RawSockaddrDatalink C.struct_sockaddr_dl - -type RawSockaddr C.struct_sockaddr - -type RawSockaddrAny C.struct_sockaddr_any - -type _Socklen C.socklen_t - -type Linger C.struct_linger - -type Iovec C.struct_iovec - -type IPMreq C.struct_ip_mreq - -type IPv6Mreq C.struct_ipv6_mreq - -type Msghdr C.struct_msghdr - -type Cmsghdr C.struct_cmsghdr - -type Inet6Pktinfo C.struct_in6_pktinfo - -type IPv6MTUInfo C.struct_ip6_mtuinfo - -type ICMPv6Filter C.struct_icmp6_filter - -const ( - SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in - SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 - SizeofSockaddrAny = C.sizeof_struct_sockaddr_any - SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un - SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl - SizeofLinger = C.sizeof_struct_linger - SizeofIPMreq = C.sizeof_struct_ip_mreq - SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq - SizeofMsghdr = C.sizeof_struct_msghdr - SizeofCmsghdr = C.sizeof_struct_cmsghdr - SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo - SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo - SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter -) - -// Ptrace requests - -const ( - PTRACE_TRACEME = C.PT_TRACE_ME - PTRACE_CONT = C.PT_CONTINUE - PTRACE_KILL = C.PT_KILL -) - -// Events (kqueue, kevent) - -type Kevent_t C.struct_kevent - -// Select - -type FdSet C.fd_set - -// Routing and interface messages - -const ( - SizeofIfMsghdr = C.sizeof_struct_if_msghdr - SizeofIfData = C.sizeof_struct_if_data - SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr - SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr - SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr - SizeofRtMsghdr = C.sizeof_struct_rt_msghdr - SizeofRtMetrics = C.sizeof_struct_rt_metrics -) - -type IfMsghdr C.struct_if_msghdr - -type IfData C.struct_if_data - -type IfaMsghdr C.struct_ifa_msghdr - -type IfmaMsghdr C.struct_ifma_msghdr - -type IfAnnounceMsghdr C.struct_if_announcemsghdr - -type RtMsghdr C.struct_rt_msghdr - -type RtMetrics C.struct_rt_metrics - -// Berkeley packet filter - -const ( - SizeofBpfVersion = C.sizeof_struct_bpf_version - SizeofBpfStat = C.sizeof_struct_bpf_stat - SizeofBpfProgram = C.sizeof_struct_bpf_program - SizeofBpfInsn = C.sizeof_struct_bpf_insn - SizeofBpfHdr = C.sizeof_struct_bpf_hdr -) - -type BpfVersion C.struct_bpf_version - -type BpfStat C.struct_bpf_stat - -type BpfProgram C.struct_bpf_program - -type BpfInsn C.struct_bpf_insn - -type BpfHdr C.struct_bpf_hdr - -// Terminal handling - -type Termios C.struct_termios - -type Winsize C.struct_winsize - -// fchmodat-like syscalls. - -const ( - AT_FDCWD = C.AT_FDCWD - AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW -) - -// poll - -type PollFd C.struct_pollfd - -const ( - POLLERR = C.POLLERR - POLLHUP = C.POLLHUP - POLLIN = C.POLLIN - POLLNVAL = C.POLLNVAL - POLLOUT = C.POLLOUT - POLLPRI = C.POLLPRI - POLLRDBAND = C.POLLRDBAND - POLLRDNORM = C.POLLRDNORM - POLLWRBAND = C.POLLWRBAND - POLLWRNORM = C.POLLWRNORM -) - -// Uname - -type Utsname C.struct_utsname diff --git a/vendor/golang.org/x/sys/unix/types_freebsd.go b/vendor/golang.org/x/sys/unix/types_freebsd.go deleted file mode 100644 index a121dc336..000000000 --- a/vendor/golang.org/x/sys/unix/types_freebsd.go +++ /dev/null @@ -1,400 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -Input to cgo -godefs. See README.md -*/ - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package unix - -/* -#define _WANT_FREEBSD11_STAT 1 -#define _WANT_FREEBSD11_STATFS 1 -#define _WANT_FREEBSD11_DIRENT 1 -#define _WANT_FREEBSD11_KEVENT 1 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -union sockaddr_all { - struct sockaddr s1; // this one gets used for fields - struct sockaddr_in s2; // these pad it out - struct sockaddr_in6 s3; - struct sockaddr_un s4; - struct sockaddr_dl s5; -}; - -struct sockaddr_any { - struct sockaddr addr; - char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; -}; - -// This structure is a duplicate of if_data on FreeBSD 8-STABLE. -// See /usr/include/net/if.h. -struct if_data8 { - u_char ifi_type; - u_char ifi_physical; - u_char ifi_addrlen; - u_char ifi_hdrlen; - u_char ifi_link_state; - u_char ifi_spare_char1; - u_char ifi_spare_char2; - u_char ifi_datalen; - u_long ifi_mtu; - u_long ifi_metric; - u_long ifi_baudrate; - u_long ifi_ipackets; - u_long ifi_ierrors; - u_long ifi_opackets; - u_long ifi_oerrors; - u_long ifi_collisions; - u_long ifi_ibytes; - u_long ifi_obytes; - u_long ifi_imcasts; - u_long ifi_omcasts; - u_long ifi_iqdrops; - u_long ifi_noproto; - u_long ifi_hwassist; -// FIXME: these are now unions, so maybe need to change definitions? -#undef ifi_epoch - time_t ifi_epoch; -#undef ifi_lastchange - struct timeval ifi_lastchange; -}; - -// This structure is a duplicate of if_msghdr on FreeBSD 8-STABLE. -// See /usr/include/net/if.h. -struct if_msghdr8 { - u_short ifm_msglen; - u_char ifm_version; - u_char ifm_type; - int ifm_addrs; - int ifm_flags; - u_short ifm_index; - struct if_data8 ifm_data; -}; -*/ -import "C" - -// Machine characteristics - -const ( - SizeofPtr = C.sizeofPtr - SizeofShort = C.sizeof_short - SizeofInt = C.sizeof_int - SizeofLong = C.sizeof_long - SizeofLongLong = C.sizeof_longlong -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong -) - -// Time - -type Timespec C.struct_timespec - -type Timeval C.struct_timeval - -// Processes - -type Rusage C.struct_rusage - -type Rlimit C.struct_rlimit - -type _Gid_t C.gid_t - -// Files - -const ( - _statfsVersion = C.STATFS_VERSION - _dirblksiz = C.DIRBLKSIZ -) - -type Stat_t C.struct_stat - -type stat_freebsd11_t C.struct_freebsd11_stat - -type Statfs_t C.struct_statfs - -type statfs_freebsd11_t C.struct_freebsd11_statfs - -type Flock_t C.struct_flock - -type Dirent C.struct_dirent - -type dirent_freebsd11 C.struct_freebsd11_dirent - -type Fsid C.struct_fsid - -// File system limits - -const ( - PathMax = C.PATH_MAX -) - -// Advice to Fadvise - -const ( - FADV_NORMAL = C.POSIX_FADV_NORMAL - FADV_RANDOM = C.POSIX_FADV_RANDOM - FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL - FADV_WILLNEED = C.POSIX_FADV_WILLNEED - FADV_DONTNEED = C.POSIX_FADV_DONTNEED - FADV_NOREUSE = C.POSIX_FADV_NOREUSE -) - -// Sockets - -type RawSockaddrInet4 C.struct_sockaddr_in - -type RawSockaddrInet6 C.struct_sockaddr_in6 - -type RawSockaddrUnix C.struct_sockaddr_un - -type RawSockaddrDatalink C.struct_sockaddr_dl - -type RawSockaddr C.struct_sockaddr - -type RawSockaddrAny C.struct_sockaddr_any - -type _Socklen C.socklen_t - -type Linger C.struct_linger - -type Iovec C.struct_iovec - -type IPMreq C.struct_ip_mreq - -type IPMreqn C.struct_ip_mreqn - -type IPv6Mreq C.struct_ipv6_mreq - -type Msghdr C.struct_msghdr - -type Cmsghdr C.struct_cmsghdr - -type Inet6Pktinfo C.struct_in6_pktinfo - -type IPv6MTUInfo C.struct_ip6_mtuinfo - -type ICMPv6Filter C.struct_icmp6_filter - -const ( - SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in - SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 - SizeofSockaddrAny = C.sizeof_struct_sockaddr_any - SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un - SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl - SizeofLinger = C.sizeof_struct_linger - SizeofIPMreq = C.sizeof_struct_ip_mreq - SizeofIPMreqn = C.sizeof_struct_ip_mreqn - SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq - SizeofMsghdr = C.sizeof_struct_msghdr - SizeofCmsghdr = C.sizeof_struct_cmsghdr - SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo - SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo - SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter -) - -// Ptrace requests - -const ( - PTRACE_ATTACH = C.PT_ATTACH - PTRACE_CONT = C.PT_CONTINUE - PTRACE_DETACH = C.PT_DETACH - PTRACE_GETFPREGS = C.PT_GETFPREGS - PTRACE_GETFSBASE = C.PT_GETFSBASE - PTRACE_GETLWPLIST = C.PT_GETLWPLIST - PTRACE_GETNUMLWPS = C.PT_GETNUMLWPS - PTRACE_GETREGS = C.PT_GETREGS - PTRACE_GETXSTATE = C.PT_GETXSTATE - PTRACE_IO = C.PT_IO - PTRACE_KILL = C.PT_KILL - PTRACE_LWPEVENTS = C.PT_LWP_EVENTS - PTRACE_LWPINFO = C.PT_LWPINFO - PTRACE_SETFPREGS = C.PT_SETFPREGS - PTRACE_SETREGS = C.PT_SETREGS - PTRACE_SINGLESTEP = C.PT_STEP - PTRACE_TRACEME = C.PT_TRACE_ME -) - -const ( - PIOD_READ_D = C.PIOD_READ_D - PIOD_WRITE_D = C.PIOD_WRITE_D - PIOD_READ_I = C.PIOD_READ_I - PIOD_WRITE_I = C.PIOD_WRITE_I -) - -const ( - PL_FLAG_BORN = C.PL_FLAG_BORN - PL_FLAG_EXITED = C.PL_FLAG_EXITED - PL_FLAG_SI = C.PL_FLAG_SI -) - -const ( - TRAP_BRKPT = C.TRAP_BRKPT - TRAP_TRACE = C.TRAP_TRACE -) - -type PtraceLwpInfoStruct C.struct_ptrace_lwpinfo - -type __Siginfo C.struct___siginfo - -type Sigset_t C.sigset_t - -type Reg C.struct_reg - -type FpReg C.struct_fpreg - -type PtraceIoDesc C.struct_ptrace_io_desc - -// Events (kqueue, kevent) - -type Kevent_t C.struct_kevent_freebsd11 - -// Select - -type FdSet C.fd_set - -// Routing and interface messages - -const ( - sizeofIfMsghdr = C.sizeof_struct_if_msghdr - SizeofIfMsghdr = C.sizeof_struct_if_msghdr8 - sizeofIfData = C.sizeof_struct_if_data - SizeofIfData = C.sizeof_struct_if_data8 - SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr - SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr - SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr - SizeofRtMsghdr = C.sizeof_struct_rt_msghdr - SizeofRtMetrics = C.sizeof_struct_rt_metrics -) - -type ifMsghdr C.struct_if_msghdr - -type IfMsghdr C.struct_if_msghdr8 - -type ifData C.struct_if_data - -type IfData C.struct_if_data8 - -type IfaMsghdr C.struct_ifa_msghdr - -type IfmaMsghdr C.struct_ifma_msghdr - -type IfAnnounceMsghdr C.struct_if_announcemsghdr - -type RtMsghdr C.struct_rt_msghdr - -type RtMetrics C.struct_rt_metrics - -// Berkeley packet filter - -const ( - SizeofBpfVersion = C.sizeof_struct_bpf_version - SizeofBpfStat = C.sizeof_struct_bpf_stat - SizeofBpfZbuf = C.sizeof_struct_bpf_zbuf - SizeofBpfProgram = C.sizeof_struct_bpf_program - SizeofBpfInsn = C.sizeof_struct_bpf_insn - SizeofBpfHdr = C.sizeof_struct_bpf_hdr - SizeofBpfZbufHeader = C.sizeof_struct_bpf_zbuf_header -) - -type BpfVersion C.struct_bpf_version - -type BpfStat C.struct_bpf_stat - -type BpfZbuf C.struct_bpf_zbuf - -type BpfProgram C.struct_bpf_program - -type BpfInsn C.struct_bpf_insn - -type BpfHdr C.struct_bpf_hdr - -type BpfZbufHeader C.struct_bpf_zbuf_header - -// Terminal handling - -type Termios C.struct_termios - -type Winsize C.struct_winsize - -// fchmodat-like syscalls. - -const ( - AT_FDCWD = C.AT_FDCWD - AT_REMOVEDIR = C.AT_REMOVEDIR - AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW - AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW -) - -// poll - -type PollFd C.struct_pollfd - -const ( - POLLERR = C.POLLERR - POLLHUP = C.POLLHUP - POLLIN = C.POLLIN - POLLINIGNEOF = C.POLLINIGNEOF - POLLNVAL = C.POLLNVAL - POLLOUT = C.POLLOUT - POLLPRI = C.POLLPRI - POLLRDBAND = C.POLLRDBAND - POLLRDNORM = C.POLLRDNORM - POLLWRBAND = C.POLLWRBAND - POLLWRNORM = C.POLLWRNORM -) - -// Capabilities - -type CapRights C.struct_cap_rights - -// Uname - -type Utsname C.struct_utsname diff --git a/vendor/golang.org/x/sys/unix/types_netbsd.go b/vendor/golang.org/x/sys/unix/types_netbsd.go deleted file mode 100644 index 4a96d72c3..000000000 --- a/vendor/golang.org/x/sys/unix/types_netbsd.go +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -Input to cgo -godefs. See README.md -*/ - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package unix - -/* -#define KERNEL -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -union sockaddr_all { - struct sockaddr s1; // this one gets used for fields - struct sockaddr_in s2; // these pad it out - struct sockaddr_in6 s3; - struct sockaddr_un s4; - struct sockaddr_dl s5; -}; - -struct sockaddr_any { - struct sockaddr addr; - char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; -}; - -*/ -import "C" - -// Machine characteristics - -const ( - SizeofPtr = C.sizeofPtr - SizeofShort = C.sizeof_short - SizeofInt = C.sizeof_int - SizeofLong = C.sizeof_long - SizeofLongLong = C.sizeof_longlong -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong -) - -// Time - -type Timespec C.struct_timespec - -type Timeval C.struct_timeval - -// Processes - -type Rusage C.struct_rusage - -type Rlimit C.struct_rlimit - -type _Gid_t C.gid_t - -// Files - -type Stat_t C.struct_stat - -type Statfs_t C.struct_statfs - -type Flock_t C.struct_flock - -type Dirent C.struct_dirent - -type Fsid C.fsid_t - -// File system limits - -const ( - PathMax = C.PATH_MAX -) - -// Advice to Fadvise - -const ( - FADV_NORMAL = C.POSIX_FADV_NORMAL - FADV_RANDOM = C.POSIX_FADV_RANDOM - FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL - FADV_WILLNEED = C.POSIX_FADV_WILLNEED - FADV_DONTNEED = C.POSIX_FADV_DONTNEED - FADV_NOREUSE = C.POSIX_FADV_NOREUSE -) - -// Sockets - -type RawSockaddrInet4 C.struct_sockaddr_in - -type RawSockaddrInet6 C.struct_sockaddr_in6 - -type RawSockaddrUnix C.struct_sockaddr_un - -type RawSockaddrDatalink C.struct_sockaddr_dl - -type RawSockaddr C.struct_sockaddr - -type RawSockaddrAny C.struct_sockaddr_any - -type _Socklen C.socklen_t - -type Linger C.struct_linger - -type Iovec C.struct_iovec - -type IPMreq C.struct_ip_mreq - -type IPv6Mreq C.struct_ipv6_mreq - -type Msghdr C.struct_msghdr - -type Cmsghdr C.struct_cmsghdr - -type Inet6Pktinfo C.struct_in6_pktinfo - -type IPv6MTUInfo C.struct_ip6_mtuinfo - -type ICMPv6Filter C.struct_icmp6_filter - -const ( - SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in - SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 - SizeofSockaddrAny = C.sizeof_struct_sockaddr_any - SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un - SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl - SizeofLinger = C.sizeof_struct_linger - SizeofIPMreq = C.sizeof_struct_ip_mreq - SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq - SizeofMsghdr = C.sizeof_struct_msghdr - SizeofCmsghdr = C.sizeof_struct_cmsghdr - SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo - SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo - SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter -) - -// Ptrace requests - -const ( - PTRACE_TRACEME = C.PT_TRACE_ME - PTRACE_CONT = C.PT_CONTINUE - PTRACE_KILL = C.PT_KILL -) - -// Events (kqueue, kevent) - -type Kevent_t C.struct_kevent - -// Select - -type FdSet C.fd_set - -// Routing and interface messages - -const ( - SizeofIfMsghdr = C.sizeof_struct_if_msghdr - SizeofIfData = C.sizeof_struct_if_data - SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr - SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr - SizeofRtMsghdr = C.sizeof_struct_rt_msghdr - SizeofRtMetrics = C.sizeof_struct_rt_metrics -) - -type IfMsghdr C.struct_if_msghdr - -type IfData C.struct_if_data - -type IfaMsghdr C.struct_ifa_msghdr - -type IfAnnounceMsghdr C.struct_if_announcemsghdr - -type RtMsghdr C.struct_rt_msghdr - -type RtMetrics C.struct_rt_metrics - -type Mclpool C.struct_mclpool - -// Berkeley packet filter - -const ( - SizeofBpfVersion = C.sizeof_struct_bpf_version - SizeofBpfStat = C.sizeof_struct_bpf_stat - SizeofBpfProgram = C.sizeof_struct_bpf_program - SizeofBpfInsn = C.sizeof_struct_bpf_insn - SizeofBpfHdr = C.sizeof_struct_bpf_hdr -) - -type BpfVersion C.struct_bpf_version - -type BpfStat C.struct_bpf_stat - -type BpfProgram C.struct_bpf_program - -type BpfInsn C.struct_bpf_insn - -type BpfHdr C.struct_bpf_hdr - -type BpfTimeval C.struct_bpf_timeval - -// Terminal handling - -type Termios C.struct_termios - -type Winsize C.struct_winsize - -type Ptmget C.struct_ptmget - -// fchmodat-like syscalls. - -const ( - AT_FDCWD = C.AT_FDCWD - AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW - AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW -) - -// poll - -type PollFd C.struct_pollfd - -const ( - POLLERR = C.POLLERR - POLLHUP = C.POLLHUP - POLLIN = C.POLLIN - POLLNVAL = C.POLLNVAL - POLLOUT = C.POLLOUT - POLLPRI = C.POLLPRI - POLLRDBAND = C.POLLRDBAND - POLLRDNORM = C.POLLRDNORM - POLLWRBAND = C.POLLWRBAND - POLLWRNORM = C.POLLWRNORM -) - -// Sysctl - -type Sysctlnode C.struct_sysctlnode - -// Uname - -type Utsname C.struct_utsname - -// Clockinfo - -const SizeofClockinfo = C.sizeof_struct_clockinfo - -type Clockinfo C.struct_clockinfo diff --git a/vendor/golang.org/x/sys/unix/types_openbsd.go b/vendor/golang.org/x/sys/unix/types_openbsd.go deleted file mode 100644 index 775cb57dc..000000000 --- a/vendor/golang.org/x/sys/unix/types_openbsd.go +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -Input to cgo -godefs. See README.md -*/ - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package unix - -/* -#define KERNEL -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -union sockaddr_all { - struct sockaddr s1; // this one gets used for fields - struct sockaddr_in s2; // these pad it out - struct sockaddr_in6 s3; - struct sockaddr_un s4; - struct sockaddr_dl s5; -}; - -struct sockaddr_any { - struct sockaddr addr; - char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; -}; - -*/ -import "C" - -// Machine characteristics - -const ( - SizeofPtr = C.sizeofPtr - SizeofShort = C.sizeof_short - SizeofInt = C.sizeof_int - SizeofLong = C.sizeof_long - SizeofLongLong = C.sizeof_longlong -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong -) - -// Time - -type Timespec C.struct_timespec - -type Timeval C.struct_timeval - -// Processes - -type Rusage C.struct_rusage - -type Rlimit C.struct_rlimit - -type _Gid_t C.gid_t - -// Files - -type Stat_t C.struct_stat - -type Statfs_t C.struct_statfs - -type Flock_t C.struct_flock - -type Dirent C.struct_dirent - -type Fsid C.fsid_t - -// File system limits - -const ( - PathMax = C.PATH_MAX -) - -// Sockets - -type RawSockaddrInet4 C.struct_sockaddr_in - -type RawSockaddrInet6 C.struct_sockaddr_in6 - -type RawSockaddrUnix C.struct_sockaddr_un - -type RawSockaddrDatalink C.struct_sockaddr_dl - -type RawSockaddr C.struct_sockaddr - -type RawSockaddrAny C.struct_sockaddr_any - -type _Socklen C.socklen_t - -type Linger C.struct_linger - -type Iovec C.struct_iovec - -type IPMreq C.struct_ip_mreq - -type IPv6Mreq C.struct_ipv6_mreq - -type Msghdr C.struct_msghdr - -type Cmsghdr C.struct_cmsghdr - -type Inet6Pktinfo C.struct_in6_pktinfo - -type IPv6MTUInfo C.struct_ip6_mtuinfo - -type ICMPv6Filter C.struct_icmp6_filter - -const ( - SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in - SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 - SizeofSockaddrAny = C.sizeof_struct_sockaddr_any - SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un - SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl - SizeofLinger = C.sizeof_struct_linger - SizeofIPMreq = C.sizeof_struct_ip_mreq - SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq - SizeofMsghdr = C.sizeof_struct_msghdr - SizeofCmsghdr = C.sizeof_struct_cmsghdr - SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo - SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo - SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter -) - -// Ptrace requests - -const ( - PTRACE_TRACEME = C.PT_TRACE_ME - PTRACE_CONT = C.PT_CONTINUE - PTRACE_KILL = C.PT_KILL -) - -// Events (kqueue, kevent) - -type Kevent_t C.struct_kevent - -// Select - -type FdSet C.fd_set - -// Routing and interface messages - -const ( - SizeofIfMsghdr = C.sizeof_struct_if_msghdr - SizeofIfData = C.sizeof_struct_if_data - SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr - SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr - SizeofRtMsghdr = C.sizeof_struct_rt_msghdr - SizeofRtMetrics = C.sizeof_struct_rt_metrics -) - -type IfMsghdr C.struct_if_msghdr - -type IfData C.struct_if_data - -type IfaMsghdr C.struct_ifa_msghdr - -type IfAnnounceMsghdr C.struct_if_announcemsghdr - -type RtMsghdr C.struct_rt_msghdr - -type RtMetrics C.struct_rt_metrics - -type Mclpool C.struct_mclpool - -// Berkeley packet filter - -const ( - SizeofBpfVersion = C.sizeof_struct_bpf_version - SizeofBpfStat = C.sizeof_struct_bpf_stat - SizeofBpfProgram = C.sizeof_struct_bpf_program - SizeofBpfInsn = C.sizeof_struct_bpf_insn - SizeofBpfHdr = C.sizeof_struct_bpf_hdr -) - -type BpfVersion C.struct_bpf_version - -type BpfStat C.struct_bpf_stat - -type BpfProgram C.struct_bpf_program - -type BpfInsn C.struct_bpf_insn - -type BpfHdr C.struct_bpf_hdr - -type BpfTimeval C.struct_bpf_timeval - -// Terminal handling - -type Termios C.struct_termios - -type Winsize C.struct_winsize - -// fchmodat-like syscalls. - -const ( - AT_FDCWD = C.AT_FDCWD - AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW - AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW -) - -// poll - -type PollFd C.struct_pollfd - -const ( - POLLERR = C.POLLERR - POLLHUP = C.POLLHUP - POLLIN = C.POLLIN - POLLNVAL = C.POLLNVAL - POLLOUT = C.POLLOUT - POLLPRI = C.POLLPRI - POLLRDBAND = C.POLLRDBAND - POLLRDNORM = C.POLLRDNORM - POLLWRBAND = C.POLLWRBAND - POLLWRNORM = C.POLLWRNORM -) - -// Signal Sets - -type Sigset_t C.sigset_t - -// Uname - -type Utsname C.struct_utsname - -// Uvmexp - -const SizeofUvmexp = C.sizeof_struct_uvmexp - -type Uvmexp C.struct_uvmexp - -// Clockinfo - -const SizeofClockinfo = C.sizeof_struct_clockinfo - -type Clockinfo C.struct_clockinfo diff --git a/vendor/golang.org/x/sys/unix/types_solaris.go b/vendor/golang.org/x/sys/unix/types_solaris.go deleted file mode 100644 index 2b716f934..000000000 --- a/vendor/golang.org/x/sys/unix/types_solaris.go +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -/* -Input to cgo -godefs. See README.md -*/ - -// +godefs map struct_in_addr [4]byte /* in_addr */ -// +godefs map struct_in6_addr [16]byte /* in6_addr */ - -package unix - -/* -#define KERNEL -// These defines ensure that builds done on newer versions of Solaris are -// backwards-compatible with older versions of Solaris and -// OpenSolaris-based derivatives. -#define __USE_SUNOS_SOCKETS__ // msghdr -#define __USE_LEGACY_PROTOTYPES__ // iovec -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -union sockaddr_all { - struct sockaddr s1; // this one gets used for fields - struct sockaddr_in s2; // these pad it out - struct sockaddr_in6 s3; - struct sockaddr_un s4; - struct sockaddr_dl s5; -}; - -struct sockaddr_any { - struct sockaddr addr; - char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; -}; - -*/ -import "C" - -// Machine characteristics - -const ( - SizeofPtr = C.sizeofPtr - SizeofShort = C.sizeof_short - SizeofInt = C.sizeof_int - SizeofLong = C.sizeof_long - SizeofLongLong = C.sizeof_longlong - PathMax = C.PATH_MAX - MaxHostNameLen = C.MAXHOSTNAMELEN -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong -) - -// Time - -type Timespec C.struct_timespec - -type Timeval C.struct_timeval - -type Timeval32 C.struct_timeval32 - -type Tms C.struct_tms - -type Utimbuf C.struct_utimbuf - -// Processes - -type Rusage C.struct_rusage - -type Rlimit C.struct_rlimit - -type _Gid_t C.gid_t - -// Files - -type Stat_t C.struct_stat - -type Flock_t C.struct_flock - -type Dirent C.struct_dirent - -// Filesystems - -type _Fsblkcnt_t C.fsblkcnt_t - -type Statvfs_t C.struct_statvfs - -// Sockets - -type RawSockaddrInet4 C.struct_sockaddr_in - -type RawSockaddrInet6 C.struct_sockaddr_in6 - -type RawSockaddrUnix C.struct_sockaddr_un - -type RawSockaddrDatalink C.struct_sockaddr_dl - -type RawSockaddr C.struct_sockaddr - -type RawSockaddrAny C.struct_sockaddr_any - -type _Socklen C.socklen_t - -type Linger C.struct_linger - -type Iovec C.struct_iovec - -type IPMreq C.struct_ip_mreq - -type IPv6Mreq C.struct_ipv6_mreq - -type Msghdr C.struct_msghdr - -type Cmsghdr C.struct_cmsghdr - -type Inet6Pktinfo C.struct_in6_pktinfo - -type IPv6MTUInfo C.struct_ip6_mtuinfo - -type ICMPv6Filter C.struct_icmp6_filter - -const ( - SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in - SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 - SizeofSockaddrAny = C.sizeof_struct_sockaddr_any - SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un - SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl - SizeofLinger = C.sizeof_struct_linger - SizeofIPMreq = C.sizeof_struct_ip_mreq - SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq - SizeofMsghdr = C.sizeof_struct_msghdr - SizeofCmsghdr = C.sizeof_struct_cmsghdr - SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo - SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo - SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter -) - -// Select - -type FdSet C.fd_set - -// Misc - -type Utsname C.struct_utsname - -type Ustat_t C.struct_ustat - -const ( - AT_FDCWD = C.AT_FDCWD - AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW - AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW - AT_REMOVEDIR = C.AT_REMOVEDIR - AT_EACCESS = C.AT_EACCESS -) - -// Routing and interface messages - -const ( - SizeofIfMsghdr = C.sizeof_struct_if_msghdr - SizeofIfData = C.sizeof_struct_if_data - SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr - SizeofRtMsghdr = C.sizeof_struct_rt_msghdr - SizeofRtMetrics = C.sizeof_struct_rt_metrics -) - -type IfMsghdr C.struct_if_msghdr - -type IfData C.struct_if_data - -type IfaMsghdr C.struct_ifa_msghdr - -type RtMsghdr C.struct_rt_msghdr - -type RtMetrics C.struct_rt_metrics - -// Berkeley packet filter - -const ( - SizeofBpfVersion = C.sizeof_struct_bpf_version - SizeofBpfStat = C.sizeof_struct_bpf_stat - SizeofBpfProgram = C.sizeof_struct_bpf_program - SizeofBpfInsn = C.sizeof_struct_bpf_insn - SizeofBpfHdr = C.sizeof_struct_bpf_hdr -) - -type BpfVersion C.struct_bpf_version - -type BpfStat C.struct_bpf_stat - -type BpfProgram C.struct_bpf_program - -type BpfInsn C.struct_bpf_insn - -type BpfTimeval C.struct_bpf_timeval - -type BpfHdr C.struct_bpf_hdr - -// Terminal handling - -type Termios C.struct_termios - -type Termio C.struct_termio - -type Winsize C.struct_winsize - -// poll - -type PollFd C.struct_pollfd - -const ( - POLLERR = C.POLLERR - POLLHUP = C.POLLHUP - POLLIN = C.POLLIN - POLLNVAL = C.POLLNVAL - POLLOUT = C.POLLOUT - POLLPRI = C.POLLPRI - POLLRDBAND = C.POLLRDBAND - POLLRDNORM = C.POLLRDNORM - POLLWRBAND = C.POLLWRBAND - POLLWRNORM = C.POLLWRNORM -) diff --git a/vendor/golang.org/x/text/encoding/charmap/maketables.go b/vendor/golang.org/x/text/encoding/charmap/maketables.go deleted file mode 100644 index f7941701e..000000000 --- a/vendor/golang.org/x/text/encoding/charmap/maketables.go +++ /dev/null @@ -1,556 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -import ( - "bufio" - "fmt" - "log" - "net/http" - "sort" - "strings" - "unicode/utf8" - - "golang.org/x/text/encoding" - "golang.org/x/text/internal/gen" -) - -const ascii = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" + - ` !"#$%&'()*+,-./0123456789:;<=>?` + - `@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_` + - "`abcdefghijklmnopqrstuvwxyz{|}~\u007f" - -var encodings = []struct { - name string - mib string - comment string - varName string - replacement byte - mapping string -}{ - { - "IBM Code Page 037", - "IBM037", - "", - "CodePage037", - 0x3f, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM037-2.1.2.ucm", - }, - { - "IBM Code Page 437", - "PC8CodePage437", - "", - "CodePage437", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM437-2.1.2.ucm", - }, - { - "IBM Code Page 850", - "PC850Multilingual", - "", - "CodePage850", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM850-2.1.2.ucm", - }, - { - "IBM Code Page 852", - "PCp852", - "", - "CodePage852", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM852-2.1.2.ucm", - }, - { - "IBM Code Page 855", - "IBM855", - "", - "CodePage855", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM855-2.1.2.ucm", - }, - { - "Windows Code Page 858", // PC latin1 with Euro - "IBM00858", - "", - "CodePage858", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/windows-858-2000.ucm", - }, - { - "IBM Code Page 860", - "IBM860", - "", - "CodePage860", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM860-2.1.2.ucm", - }, - { - "IBM Code Page 862", - "PC862LatinHebrew", - "", - "CodePage862", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM862-2.1.2.ucm", - }, - { - "IBM Code Page 863", - "IBM863", - "", - "CodePage863", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM863-2.1.2.ucm", - }, - { - "IBM Code Page 865", - "IBM865", - "", - "CodePage865", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM865-2.1.2.ucm", - }, - { - "IBM Code Page 866", - "IBM866", - "", - "CodePage866", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-ibm866.txt", - }, - { - "IBM Code Page 1047", - "IBM1047", - "", - "CodePage1047", - 0x3f, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM1047-2.1.2.ucm", - }, - { - "IBM Code Page 1140", - "IBM01140", - "", - "CodePage1140", - 0x3f, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/ibm-1140_P100-1997.ucm", - }, - { - "ISO 8859-1", - "ISOLatin1", - "", - "ISO8859_1", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/iso-8859_1-1998.ucm", - }, - { - "ISO 8859-2", - "ISOLatin2", - "", - "ISO8859_2", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-2.txt", - }, - { - "ISO 8859-3", - "ISOLatin3", - "", - "ISO8859_3", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-3.txt", - }, - { - "ISO 8859-4", - "ISOLatin4", - "", - "ISO8859_4", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-4.txt", - }, - { - "ISO 8859-5", - "ISOLatinCyrillic", - "", - "ISO8859_5", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-5.txt", - }, - { - "ISO 8859-6", - "ISOLatinArabic", - "", - "ISO8859_6,ISO8859_6E,ISO8859_6I", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-6.txt", - }, - { - "ISO 8859-7", - "ISOLatinGreek", - "", - "ISO8859_7", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-7.txt", - }, - { - "ISO 8859-8", - "ISOLatinHebrew", - "", - "ISO8859_8,ISO8859_8E,ISO8859_8I", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-8.txt", - }, - { - "ISO 8859-9", - "ISOLatin5", - "", - "ISO8859_9", - encoding.ASCIISub, - "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/iso-8859_9-1999.ucm", - }, - { - "ISO 8859-10", - "ISOLatin6", - "", - "ISO8859_10", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-10.txt", - }, - { - "ISO 8859-13", - "ISO885913", - "", - "ISO8859_13", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-13.txt", - }, - { - "ISO 8859-14", - "ISO885914", - "", - "ISO8859_14", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-14.txt", - }, - { - "ISO 8859-15", - "ISO885915", - "", - "ISO8859_15", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-15.txt", - }, - { - "ISO 8859-16", - "ISO885916", - "", - "ISO8859_16", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-iso-8859-16.txt", - }, - { - "KOI8-R", - "KOI8R", - "", - "KOI8R", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-koi8-r.txt", - }, - { - "KOI8-U", - "KOI8U", - "", - "KOI8U", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-koi8-u.txt", - }, - { - "Macintosh", - "Macintosh", - "", - "Macintosh", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-macintosh.txt", - }, - { - "Macintosh Cyrillic", - "MacintoshCyrillic", - "", - "MacintoshCyrillic", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-x-mac-cyrillic.txt", - }, - { - "Windows 874", - "Windows874", - "", - "Windows874", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-874.txt", - }, - { - "Windows 1250", - "Windows1250", - "", - "Windows1250", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1250.txt", - }, - { - "Windows 1251", - "Windows1251", - "", - "Windows1251", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1251.txt", - }, - { - "Windows 1252", - "Windows1252", - "", - "Windows1252", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1252.txt", - }, - { - "Windows 1253", - "Windows1253", - "", - "Windows1253", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1253.txt", - }, - { - "Windows 1254", - "Windows1254", - "", - "Windows1254", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1254.txt", - }, - { - "Windows 1255", - "Windows1255", - "", - "Windows1255", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1255.txt", - }, - { - "Windows 1256", - "Windows1256", - "", - "Windows1256", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1256.txt", - }, - { - "Windows 1257", - "Windows1257", - "", - "Windows1257", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1257.txt", - }, - { - "Windows 1258", - "Windows1258", - "", - "Windows1258", - encoding.ASCIISub, - "http://encoding.spec.whatwg.org/index-windows-1258.txt", - }, - { - "X-User-Defined", - "XUserDefined", - "It is defined at http://encoding.spec.whatwg.org/#x-user-defined", - "XUserDefined", - encoding.ASCIISub, - ascii + - "\uf780\uf781\uf782\uf783\uf784\uf785\uf786\uf787" + - "\uf788\uf789\uf78a\uf78b\uf78c\uf78d\uf78e\uf78f" + - "\uf790\uf791\uf792\uf793\uf794\uf795\uf796\uf797" + - "\uf798\uf799\uf79a\uf79b\uf79c\uf79d\uf79e\uf79f" + - "\uf7a0\uf7a1\uf7a2\uf7a3\uf7a4\uf7a5\uf7a6\uf7a7" + - "\uf7a8\uf7a9\uf7aa\uf7ab\uf7ac\uf7ad\uf7ae\uf7af" + - "\uf7b0\uf7b1\uf7b2\uf7b3\uf7b4\uf7b5\uf7b6\uf7b7" + - "\uf7b8\uf7b9\uf7ba\uf7bb\uf7bc\uf7bd\uf7be\uf7bf" + - "\uf7c0\uf7c1\uf7c2\uf7c3\uf7c4\uf7c5\uf7c6\uf7c7" + - "\uf7c8\uf7c9\uf7ca\uf7cb\uf7cc\uf7cd\uf7ce\uf7cf" + - "\uf7d0\uf7d1\uf7d2\uf7d3\uf7d4\uf7d5\uf7d6\uf7d7" + - "\uf7d8\uf7d9\uf7da\uf7db\uf7dc\uf7dd\uf7de\uf7df" + - "\uf7e0\uf7e1\uf7e2\uf7e3\uf7e4\uf7e5\uf7e6\uf7e7" + - "\uf7e8\uf7e9\uf7ea\uf7eb\uf7ec\uf7ed\uf7ee\uf7ef" + - "\uf7f0\uf7f1\uf7f2\uf7f3\uf7f4\uf7f5\uf7f6\uf7f7" + - "\uf7f8\uf7f9\uf7fa\uf7fb\uf7fc\uf7fd\uf7fe\uf7ff", - }, -} - -func getWHATWG(url string) string { - res, err := http.Get(url) - if err != nil { - log.Fatalf("%q: Get: %v", url, err) - } - defer res.Body.Close() - - mapping := make([]rune, 128) - for i := range mapping { - mapping[i] = '\ufffd' - } - - scanner := bufio.NewScanner(res.Body) - for scanner.Scan() { - s := strings.TrimSpace(scanner.Text()) - if s == "" || s[0] == '#' { - continue - } - x, y := 0, 0 - if _, err := fmt.Sscanf(s, "%d\t0x%x", &x, &y); err != nil { - log.Fatalf("could not parse %q", s) - } - if x < 0 || 128 <= x { - log.Fatalf("code %d is out of range", x) - } - if 0x80 <= y && y < 0xa0 { - // We diverge from the WHATWG spec by mapping control characters - // in the range [0x80, 0xa0) to U+FFFD. - continue - } - mapping[x] = rune(y) - } - return ascii + string(mapping) -} - -func getUCM(url string) string { - res, err := http.Get(url) - if err != nil { - log.Fatalf("%q: Get: %v", url, err) - } - defer res.Body.Close() - - mapping := make([]rune, 256) - for i := range mapping { - mapping[i] = '\ufffd' - } - - charsFound := 0 - scanner := bufio.NewScanner(res.Body) - for scanner.Scan() { - s := strings.TrimSpace(scanner.Text()) - if s == "" || s[0] == '#' { - continue - } - var c byte - var r rune - if _, err := fmt.Sscanf(s, ` \x%x |0`, &r, &c); err != nil { - continue - } - mapping[c] = r - charsFound++ - } - - if charsFound < 200 { - log.Fatalf("%q: only %d characters found (wrong page format?)", url, charsFound) - } - - return string(mapping) -} - -func main() { - mibs := map[string]bool{} - all := []string{} - - w := gen.NewCodeWriter() - defer w.WriteGoFile("tables.go", "charmap") - - printf := func(s string, a ...interface{}) { fmt.Fprintf(w, s, a...) } - - printf("import (\n") - printf("\t\"golang.org/x/text/encoding\"\n") - printf("\t\"golang.org/x/text/encoding/internal/identifier\"\n") - printf(")\n\n") - for _, e := range encodings { - varNames := strings.Split(e.varName, ",") - all = append(all, varNames...) - varName := varNames[0] - switch { - case strings.HasPrefix(e.mapping, "http://encoding.spec.whatwg.org/"): - e.mapping = getWHATWG(e.mapping) - case strings.HasPrefix(e.mapping, "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/"): - e.mapping = getUCM(e.mapping) - } - - asciiSuperset, low := strings.HasPrefix(e.mapping, ascii), 0x00 - if asciiSuperset { - low = 0x80 - } - lvn := 1 - if strings.HasPrefix(varName, "ISO") || strings.HasPrefix(varName, "KOI") { - lvn = 3 - } - lowerVarName := strings.ToLower(varName[:lvn]) + varName[lvn:] - printf("// %s is the %s encoding.\n", varName, e.name) - if e.comment != "" { - printf("//\n// %s\n", e.comment) - } - printf("var %s *Charmap = &%s\n\nvar %s = Charmap{\nname: %q,\n", - varName, lowerVarName, lowerVarName, e.name) - if mibs[e.mib] { - log.Fatalf("MIB type %q declared multiple times.", e.mib) - } - printf("mib: identifier.%s,\n", e.mib) - printf("asciiSuperset: %t,\n", asciiSuperset) - printf("low: 0x%02x,\n", low) - printf("replacement: 0x%02x,\n", e.replacement) - - printf("decode: [256]utf8Enc{\n") - i, backMapping := 0, map[rune]byte{} - for _, c := range e.mapping { - if _, ok := backMapping[c]; !ok && c != utf8.RuneError { - backMapping[c] = byte(i) - } - var buf [8]byte - n := utf8.EncodeRune(buf[:], c) - if n > 3 { - panic(fmt.Sprintf("rune %q (%U) is too long", c, c)) - } - printf("{%d,[3]byte{0x%02x,0x%02x,0x%02x}},", n, buf[0], buf[1], buf[2]) - if i%2 == 1 { - printf("\n") - } - i++ - } - printf("},\n") - - printf("encode: [256]uint32{\n") - encode := make([]uint32, 0, 256) - for c, i := range backMapping { - encode = append(encode, uint32(i)<<24|uint32(c)) - } - sort.Sort(byRune(encode)) - for len(encode) < cap(encode) { - encode = append(encode, encode[len(encode)-1]) - } - for i, enc := range encode { - printf("0x%08x,", enc) - if i%8 == 7 { - printf("\n") - } - } - printf("},\n}\n") - - // Add an estimate of the size of a single Charmap{} struct value, which - // includes two 256 elem arrays of 4 bytes and some extra fields, which - // align to 3 uint64s on 64-bit architectures. - w.Size += 2*4*256 + 3*8 - } - // TODO: add proper line breaking. - printf("var listAll = []encoding.Encoding{\n%s,\n}\n\n", strings.Join(all, ",\n")) -} - -type byRune []uint32 - -func (b byRune) Len() int { return len(b) } -func (b byRune) Less(i, j int) bool { return b[i]&0xffffff < b[j]&0xffffff } -func (b byRune) Swap(i, j int) { b[i], b[j] = b[j], b[i] } diff --git a/vendor/golang.org/x/text/encoding/htmlindex/gen.go b/vendor/golang.org/x/text/encoding/htmlindex/gen.go deleted file mode 100644 index ac6b4a77f..000000000 --- a/vendor/golang.org/x/text/encoding/htmlindex/gen.go +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "log" - "strings" - - "golang.org/x/text/internal/gen" -) - -type group struct { - Encodings []struct { - Labels []string - Name string - } -} - -func main() { - gen.Init() - - r := gen.Open("https://encoding.spec.whatwg.org", "whatwg", "encodings.json") - var groups []group - if err := json.NewDecoder(r).Decode(&groups); err != nil { - log.Fatalf("Error reading encodings.json: %v", err) - } - - w := &bytes.Buffer{} - fmt.Fprintln(w, "type htmlEncoding byte") - fmt.Fprintln(w, "const (") - for i, g := range groups { - for _, e := range g.Encodings { - key := strings.ToLower(e.Name) - name := consts[key] - if name == "" { - log.Fatalf("No const defined for %s.", key) - } - if i == 0 { - fmt.Fprintf(w, "%s htmlEncoding = iota\n", name) - } else { - fmt.Fprintf(w, "%s\n", name) - } - } - } - fmt.Fprintln(w, "numEncodings") - fmt.Fprint(w, ")\n\n") - - fmt.Fprintln(w, "var canonical = [numEncodings]string{") - for _, g := range groups { - for _, e := range g.Encodings { - fmt.Fprintf(w, "%q,\n", strings.ToLower(e.Name)) - } - } - fmt.Fprint(w, "}\n\n") - - fmt.Fprintln(w, "var nameMap = map[string]htmlEncoding{") - for _, g := range groups { - for _, e := range g.Encodings { - for _, l := range e.Labels { - key := strings.ToLower(e.Name) - name := consts[key] - fmt.Fprintf(w, "%q: %s,\n", l, name) - } - } - } - fmt.Fprint(w, "}\n\n") - - var tags []string - fmt.Fprintln(w, "var localeMap = []htmlEncoding{") - for _, loc := range locales { - tags = append(tags, loc.tag) - fmt.Fprintf(w, "%s, // %s \n", consts[loc.name], loc.tag) - } - fmt.Fprint(w, "}\n\n") - - fmt.Fprintf(w, "const locales = %q\n", strings.Join(tags, " ")) - - gen.WriteGoFile("tables.go", "htmlindex", w.Bytes()) -} - -// consts maps canonical encoding name to internal constant. -var consts = map[string]string{ - "utf-8": "utf8", - "ibm866": "ibm866", - "iso-8859-2": "iso8859_2", - "iso-8859-3": "iso8859_3", - "iso-8859-4": "iso8859_4", - "iso-8859-5": "iso8859_5", - "iso-8859-6": "iso8859_6", - "iso-8859-7": "iso8859_7", - "iso-8859-8": "iso8859_8", - "iso-8859-8-i": "iso8859_8I", - "iso-8859-10": "iso8859_10", - "iso-8859-13": "iso8859_13", - "iso-8859-14": "iso8859_14", - "iso-8859-15": "iso8859_15", - "iso-8859-16": "iso8859_16", - "koi8-r": "koi8r", - "koi8-u": "koi8u", - "macintosh": "macintosh", - "windows-874": "windows874", - "windows-1250": "windows1250", - "windows-1251": "windows1251", - "windows-1252": "windows1252", - "windows-1253": "windows1253", - "windows-1254": "windows1254", - "windows-1255": "windows1255", - "windows-1256": "windows1256", - "windows-1257": "windows1257", - "windows-1258": "windows1258", - "x-mac-cyrillic": "macintoshCyrillic", - "gbk": "gbk", - "gb18030": "gb18030", - // "hz-gb-2312": "hzgb2312", // Was removed from WhatWG - "big5": "big5", - "euc-jp": "eucjp", - "iso-2022-jp": "iso2022jp", - "shift_jis": "shiftJIS", - "euc-kr": "euckr", - "replacement": "replacement", - "utf-16be": "utf16be", - "utf-16le": "utf16le", - "x-user-defined": "xUserDefined", -} - -// locales is taken from -// https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm. -var locales = []struct{ tag, name string }{ - // The default value. Explicitly state latin to benefit from the exact - // script option, while still making 1252 the default encoding for languages - // written in Latin script. - {"und_Latn", "windows-1252"}, - {"ar", "windows-1256"}, - {"ba", "windows-1251"}, - {"be", "windows-1251"}, - {"bg", "windows-1251"}, - {"cs", "windows-1250"}, - {"el", "iso-8859-7"}, - {"et", "windows-1257"}, - {"fa", "windows-1256"}, - {"he", "windows-1255"}, - {"hr", "windows-1250"}, - {"hu", "iso-8859-2"}, - {"ja", "shift_jis"}, - {"kk", "windows-1251"}, - {"ko", "euc-kr"}, - {"ku", "windows-1254"}, - {"ky", "windows-1251"}, - {"lt", "windows-1257"}, - {"lv", "windows-1257"}, - {"mk", "windows-1251"}, - {"pl", "iso-8859-2"}, - {"ru", "windows-1251"}, - {"sah", "windows-1251"}, - {"sk", "windows-1250"}, - {"sl", "iso-8859-2"}, - {"sr", "windows-1251"}, - {"tg", "windows-1251"}, - {"th", "windows-874"}, - {"tr", "windows-1254"}, - {"tt", "windows-1251"}, - {"uk", "windows-1251"}, - {"vi", "windows-1258"}, - {"zh-hans", "gb18030"}, - {"zh-hant", "big5"}, -} diff --git a/vendor/golang.org/x/text/encoding/internal/identifier/gen.go b/vendor/golang.org/x/text/encoding/internal/identifier/gen.go deleted file mode 100644 index 26cfef9c6..000000000 --- a/vendor/golang.org/x/text/encoding/internal/identifier/gen.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -import ( - "bytes" - "encoding/xml" - "fmt" - "io" - "log" - "strings" - - "golang.org/x/text/internal/gen" -) - -type registry struct { - XMLName xml.Name `xml:"registry"` - Updated string `xml:"updated"` - Registry []struct { - ID string `xml:"id,attr"` - Record []struct { - Name string `xml:"name"` - Xref []struct { - Type string `xml:"type,attr"` - Data string `xml:"data,attr"` - } `xml:"xref"` - Desc struct { - Data string `xml:",innerxml"` - // Any []struct { - // Data string `xml:",chardata"` - // } `xml:",any"` - // Data string `xml:",chardata"` - } `xml:"description,"` - MIB string `xml:"value"` - Alias []string `xml:"alias"` - MIME string `xml:"preferred_alias"` - } `xml:"record"` - } `xml:"registry"` -} - -func main() { - r := gen.OpenIANAFile("assignments/character-sets/character-sets.xml") - reg := ®istry{} - if err := xml.NewDecoder(r).Decode(®); err != nil && err != io.EOF { - log.Fatalf("Error decoding charset registry: %v", err) - } - if len(reg.Registry) == 0 || reg.Registry[0].ID != "character-sets-1" { - log.Fatalf("Unexpected ID %s", reg.Registry[0].ID) - } - - w := &bytes.Buffer{} - fmt.Fprintf(w, "const (\n") - for _, rec := range reg.Registry[0].Record { - constName := "" - for _, a := range rec.Alias { - if strings.HasPrefix(a, "cs") && strings.IndexByte(a, '-') == -1 { - // Some of the constant definitions have comments in them. Strip those. - constName = strings.Title(strings.SplitN(a[2:], "\n", 2)[0]) - } - } - if constName == "" { - switch rec.MIB { - case "2085": - constName = "HZGB2312" // Not listed as alias for some reason. - default: - log.Fatalf("No cs alias defined for %s.", rec.MIB) - } - } - if rec.MIME != "" { - rec.MIME = fmt.Sprintf(" (MIME: %s)", rec.MIME) - } - fmt.Fprintf(w, "// %s is the MIB identifier with IANA name %s%s.\n//\n", constName, rec.Name, rec.MIME) - if len(rec.Desc.Data) > 0 { - fmt.Fprint(w, "// ") - d := xml.NewDecoder(strings.NewReader(rec.Desc.Data)) - inElem := true - attr := "" - for { - t, err := d.Token() - if err != nil { - if err != io.EOF { - log.Fatal(err) - } - break - } - switch x := t.(type) { - case xml.CharData: - attr = "" // Don't need attribute info. - a := bytes.Split([]byte(x), []byte("\n")) - for i, b := range a { - if b = bytes.TrimSpace(b); len(b) != 0 { - if !inElem && i > 0 { - fmt.Fprint(w, "\n// ") - } - inElem = false - fmt.Fprintf(w, "%s ", string(b)) - } - } - case xml.StartElement: - if x.Name.Local == "xref" { - inElem = true - use := false - for _, a := range x.Attr { - if a.Name.Local == "type" { - use = use || a.Value != "person" - } - if a.Name.Local == "data" && use { - // Patch up URLs to use https. From some links, the - // https version is different from the http one. - s := a.Value - s = strings.Replace(s, "http://", "https://", -1) - s = strings.Replace(s, "/unicode/", "/", -1) - attr = s + " " - } - } - } - case xml.EndElement: - inElem = false - fmt.Fprint(w, attr) - } - } - fmt.Fprint(w, "\n") - } - for _, x := range rec.Xref { - switch x.Type { - case "rfc": - fmt.Fprintf(w, "// Reference: %s\n", strings.ToUpper(x.Data)) - case "uri": - fmt.Fprintf(w, "// Reference: %s\n", x.Data) - } - } - fmt.Fprintf(w, "%s MIB = %s\n", constName, rec.MIB) - fmt.Fprintln(w) - } - fmt.Fprintln(w, ")") - - gen.WriteGoFile("mib.go", "identifier", w.Bytes()) -} diff --git a/vendor/golang.org/x/text/encoding/japanese/maketables.go b/vendor/golang.org/x/text/encoding/japanese/maketables.go deleted file mode 100644 index 023957a67..000000000 --- a/vendor/golang.org/x/text/encoding/japanese/maketables.go +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -// This program generates tables.go: -// go run maketables.go | gofmt > tables.go - -// TODO: Emoji extensions? -// https://www.unicode.org/faq/emoji_dingbats.html -// https://www.unicode.org/Public/UNIDATA/EmojiSources.txt - -import ( - "bufio" - "fmt" - "log" - "net/http" - "sort" - "strings" -) - -type entry struct { - jisCode, table int -} - -func main() { - fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n") - fmt.Printf("// Package japanese provides Japanese encodings such as EUC-JP and Shift JIS.\n") - fmt.Printf(`package japanese // import "golang.org/x/text/encoding/japanese"` + "\n\n") - - reverse := [65536]entry{} - for i := range reverse { - reverse[i].table = -1 - } - - tables := []struct { - url string - name string - }{ - {"http://encoding.spec.whatwg.org/index-jis0208.txt", "0208"}, - {"http://encoding.spec.whatwg.org/index-jis0212.txt", "0212"}, - } - for i, table := range tables { - res, err := http.Get(table.url) - if err != nil { - log.Fatalf("%q: Get: %v", table.url, err) - } - defer res.Body.Close() - - mapping := [65536]uint16{} - - scanner := bufio.NewScanner(res.Body) - for scanner.Scan() { - s := strings.TrimSpace(scanner.Text()) - if s == "" || s[0] == '#' { - continue - } - x, y := 0, uint16(0) - if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil { - log.Fatalf("%q: could not parse %q", table.url, s) - } - if x < 0 || 120*94 <= x { - log.Fatalf("%q: JIS code %d is out of range", table.url, x) - } - mapping[x] = y - if reverse[y].table == -1 { - reverse[y] = entry{jisCode: x, table: i} - } - } - if err := scanner.Err(); err != nil { - log.Fatalf("%q: scanner error: %v", table.url, err) - } - - fmt.Printf("// jis%sDecode is the decoding table from JIS %s code to Unicode.\n// It is defined at %s\n", - table.name, table.name, table.url) - fmt.Printf("var jis%sDecode = [...]uint16{\n", table.name) - for i, m := range mapping { - if m != 0 { - fmt.Printf("\t%d: 0x%04X,\n", i, m) - } - } - fmt.Printf("}\n\n") - } - - // Any run of at least separation continuous zero entries in the reverse map will - // be a separate encode table. - const separation = 1024 - - intervals := []interval(nil) - low, high := -1, -1 - for i, v := range reverse { - if v.table == -1 { - continue - } - if low < 0 { - low = i - } else if i-high >= separation { - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - low = i - } - high = i + 1 - } - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - sort.Sort(byDecreasingLength(intervals)) - - fmt.Printf("const (\n") - fmt.Printf("\tjis0208 = 1\n") - fmt.Printf("\tjis0212 = 2\n") - fmt.Printf("\tcodeMask = 0x7f\n") - fmt.Printf("\tcodeShift = 7\n") - fmt.Printf("\ttableShift = 14\n") - fmt.Printf(")\n\n") - - fmt.Printf("const numEncodeTables = %d\n\n", len(intervals)) - fmt.Printf("// encodeX are the encoding tables from Unicode to JIS code,\n") - fmt.Printf("// sorted by decreasing length.\n") - for i, v := range intervals { - fmt.Printf("// encode%d: %5d entries for runes in [%5d, %5d).\n", i, v.len(), v.low, v.high) - } - fmt.Printf("//\n") - fmt.Printf("// The high two bits of the value record whether the JIS code comes from the\n") - fmt.Printf("// JIS0208 table (high bits == 1) or the JIS0212 table (high bits == 2).\n") - fmt.Printf("// The low 14 bits are two 7-bit unsigned integers j1 and j2 that form the\n") - fmt.Printf("// JIS code (94*j1 + j2) within that table.\n") - fmt.Printf("\n") - - for i, v := range intervals { - fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high) - fmt.Printf("var encode%d = [...]uint16{\n", i) - for j := v.low; j < v.high; j++ { - x := reverse[j] - if x.table == -1 { - continue - } - fmt.Printf("\t%d - %d: jis%s<<14 | 0x%02X<<7 | 0x%02X,\n", - j, v.low, tables[x.table].name, x.jisCode/94, x.jisCode%94) - } - fmt.Printf("}\n\n") - } -} - -// interval is a half-open interval [low, high). -type interval struct { - low, high int -} - -func (i interval) len() int { return i.high - i.low } - -// byDecreasingLength sorts intervals by decreasing length. -type byDecreasingLength []interval - -func (b byDecreasingLength) Len() int { return len(b) } -func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() } -func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] } diff --git a/vendor/golang.org/x/text/encoding/korean/maketables.go b/vendor/golang.org/x/text/encoding/korean/maketables.go deleted file mode 100644 index c84034fb6..000000000 --- a/vendor/golang.org/x/text/encoding/korean/maketables.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -// This program generates tables.go: -// go run maketables.go | gofmt > tables.go - -import ( - "bufio" - "fmt" - "log" - "net/http" - "sort" - "strings" -) - -func main() { - fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n") - fmt.Printf("// Package korean provides Korean encodings such as EUC-KR.\n") - fmt.Printf(`package korean // import "golang.org/x/text/encoding/korean"` + "\n\n") - - res, err := http.Get("http://encoding.spec.whatwg.org/index-euc-kr.txt") - if err != nil { - log.Fatalf("Get: %v", err) - } - defer res.Body.Close() - - mapping := [65536]uint16{} - reverse := [65536]uint16{} - - scanner := bufio.NewScanner(res.Body) - for scanner.Scan() { - s := strings.TrimSpace(scanner.Text()) - if s == "" || s[0] == '#' { - continue - } - x, y := uint16(0), uint16(0) - if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil { - log.Fatalf("could not parse %q", s) - } - if x < 0 || 178*(0xc7-0x81)+(0xfe-0xc7)*94+(0xff-0xa1) <= x { - log.Fatalf("EUC-KR code %d is out of range", x) - } - mapping[x] = y - if reverse[y] == 0 { - c0, c1 := uint16(0), uint16(0) - if x < 178*(0xc7-0x81) { - c0 = uint16(x/178) + 0x81 - c1 = uint16(x % 178) - switch { - case c1 < 1*26: - c1 += 0x41 - case c1 < 2*26: - c1 += 0x47 - default: - c1 += 0x4d - } - } else { - x -= 178 * (0xc7 - 0x81) - c0 = uint16(x/94) + 0xc7 - c1 = uint16(x%94) + 0xa1 - } - reverse[y] = c0<<8 | c1 - } - } - if err := scanner.Err(); err != nil { - log.Fatalf("scanner error: %v", err) - } - - fmt.Printf("// decode is the decoding table from EUC-KR code to Unicode.\n") - fmt.Printf("// It is defined at http://encoding.spec.whatwg.org/index-euc-kr.txt\n") - fmt.Printf("var decode = [...]uint16{\n") - for i, v := range mapping { - if v != 0 { - fmt.Printf("\t%d: 0x%04X,\n", i, v) - } - } - fmt.Printf("}\n\n") - - // Any run of at least separation continuous zero entries in the reverse map will - // be a separate encode table. - const separation = 1024 - - intervals := []interval(nil) - low, high := -1, -1 - for i, v := range reverse { - if v == 0 { - continue - } - if low < 0 { - low = i - } else if i-high >= separation { - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - low = i - } - high = i + 1 - } - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - sort.Sort(byDecreasingLength(intervals)) - - fmt.Printf("const numEncodeTables = %d\n\n", len(intervals)) - fmt.Printf("// encodeX are the encoding tables from Unicode to EUC-KR code,\n") - fmt.Printf("// sorted by decreasing length.\n") - for i, v := range intervals { - fmt.Printf("// encode%d: %5d entries for runes in [%5d, %5d).\n", i, v.len(), v.low, v.high) - } - fmt.Printf("\n") - - for i, v := range intervals { - fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high) - fmt.Printf("var encode%d = [...]uint16{\n", i) - for j := v.low; j < v.high; j++ { - x := reverse[j] - if x == 0 { - continue - } - fmt.Printf("\t%d-%d: 0x%04X,\n", j, v.low, x) - } - fmt.Printf("}\n\n") - } -} - -// interval is a half-open interval [low, high). -type interval struct { - low, high int -} - -func (i interval) len() int { return i.high - i.low } - -// byDecreasingLength sorts intervals by decreasing length. -type byDecreasingLength []interval - -func (b byDecreasingLength) Len() int { return len(b) } -func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() } -func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] } diff --git a/vendor/golang.org/x/text/encoding/simplifiedchinese/maketables.go b/vendor/golang.org/x/text/encoding/simplifiedchinese/maketables.go deleted file mode 100644 index 55016c786..000000000 --- a/vendor/golang.org/x/text/encoding/simplifiedchinese/maketables.go +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -// This program generates tables.go: -// go run maketables.go | gofmt > tables.go - -import ( - "bufio" - "fmt" - "log" - "net/http" - "sort" - "strings" -) - -func main() { - fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n") - fmt.Printf("// Package simplifiedchinese provides Simplified Chinese encodings such as GBK.\n") - fmt.Printf(`package simplifiedchinese // import "golang.org/x/text/encoding/simplifiedchinese"` + "\n\n") - - printGB18030() - printGBK() -} - -func printGB18030() { - res, err := http.Get("http://encoding.spec.whatwg.org/index-gb18030.txt") - if err != nil { - log.Fatalf("Get: %v", err) - } - defer res.Body.Close() - - fmt.Printf("// gb18030 is the table from http://encoding.spec.whatwg.org/index-gb18030.txt\n") - fmt.Printf("var gb18030 = [...][2]uint16{\n") - scanner := bufio.NewScanner(res.Body) - for scanner.Scan() { - s := strings.TrimSpace(scanner.Text()) - if s == "" || s[0] == '#' { - continue - } - x, y := uint32(0), uint32(0) - if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil { - log.Fatalf("could not parse %q", s) - } - if x < 0x10000 && y < 0x10000 { - fmt.Printf("\t{0x%04x, 0x%04x},\n", x, y) - } - } - fmt.Printf("}\n\n") -} - -func printGBK() { - res, err := http.Get("http://encoding.spec.whatwg.org/index-gbk.txt") - if err != nil { - log.Fatalf("Get: %v", err) - } - defer res.Body.Close() - - mapping := [65536]uint16{} - reverse := [65536]uint16{} - - scanner := bufio.NewScanner(res.Body) - for scanner.Scan() { - s := strings.TrimSpace(scanner.Text()) - if s == "" || s[0] == '#' { - continue - } - x, y := uint16(0), uint16(0) - if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil { - log.Fatalf("could not parse %q", s) - } - if x < 0 || 126*190 <= x { - log.Fatalf("GBK code %d is out of range", x) - } - mapping[x] = y - if reverse[y] == 0 { - c0, c1 := x/190, x%190 - if c1 >= 0x3f { - c1++ - } - reverse[y] = (0x81+c0)<<8 | (0x40 + c1) - } - } - if err := scanner.Err(); err != nil { - log.Fatalf("scanner error: %v", err) - } - - fmt.Printf("// decode is the decoding table from GBK code to Unicode.\n") - fmt.Printf("// It is defined at http://encoding.spec.whatwg.org/index-gbk.txt\n") - fmt.Printf("var decode = [...]uint16{\n") - for i, v := range mapping { - if v != 0 { - fmt.Printf("\t%d: 0x%04X,\n", i, v) - } - } - fmt.Printf("}\n\n") - - // Any run of at least separation continuous zero entries in the reverse map will - // be a separate encode table. - const separation = 1024 - - intervals := []interval(nil) - low, high := -1, -1 - for i, v := range reverse { - if v == 0 { - continue - } - if low < 0 { - low = i - } else if i-high >= separation { - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - low = i - } - high = i + 1 - } - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - sort.Sort(byDecreasingLength(intervals)) - - fmt.Printf("const numEncodeTables = %d\n\n", len(intervals)) - fmt.Printf("// encodeX are the encoding tables from Unicode to GBK code,\n") - fmt.Printf("// sorted by decreasing length.\n") - for i, v := range intervals { - fmt.Printf("// encode%d: %5d entries for runes in [%5d, %5d).\n", i, v.len(), v.low, v.high) - } - fmt.Printf("\n") - - for i, v := range intervals { - fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high) - fmt.Printf("var encode%d = [...]uint16{\n", i) - for j := v.low; j < v.high; j++ { - x := reverse[j] - if x == 0 { - continue - } - fmt.Printf("\t%d-%d: 0x%04X,\n", j, v.low, x) - } - fmt.Printf("}\n\n") - } -} - -// interval is a half-open interval [low, high). -type interval struct { - low, high int -} - -func (i interval) len() int { return i.high - i.low } - -// byDecreasingLength sorts intervals by decreasing length. -type byDecreasingLength []interval - -func (b byDecreasingLength) Len() int { return len(b) } -func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() } -func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] } diff --git a/vendor/golang.org/x/text/encoding/traditionalchinese/maketables.go b/vendor/golang.org/x/text/encoding/traditionalchinese/maketables.go deleted file mode 100644 index cf7fdb31a..000000000 --- a/vendor/golang.org/x/text/encoding/traditionalchinese/maketables.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -// This program generates tables.go: -// go run maketables.go | gofmt > tables.go - -import ( - "bufio" - "fmt" - "log" - "net/http" - "sort" - "strings" -) - -func main() { - fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n") - fmt.Printf("// Package traditionalchinese provides Traditional Chinese encodings such as Big5.\n") - fmt.Printf(`package traditionalchinese // import "golang.org/x/text/encoding/traditionalchinese"` + "\n\n") - - res, err := http.Get("http://encoding.spec.whatwg.org/index-big5.txt") - if err != nil { - log.Fatalf("Get: %v", err) - } - defer res.Body.Close() - - mapping := [65536]uint32{} - reverse := [65536 * 4]uint16{} - - scanner := bufio.NewScanner(res.Body) - for scanner.Scan() { - s := strings.TrimSpace(scanner.Text()) - if s == "" || s[0] == '#' { - continue - } - x, y := uint16(0), uint32(0) - if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil { - log.Fatalf("could not parse %q", s) - } - if x < 0 || 126*157 <= x { - log.Fatalf("Big5 code %d is out of range", x) - } - mapping[x] = y - - // The WHATWG spec http://encoding.spec.whatwg.org/#indexes says that - // "The index pointer for code point in index is the first pointer - // corresponding to code point in index", which would normally mean - // that the code below should be guarded by "if reverse[y] == 0", but - // last instead of first seems to match the behavior of - // "iconv -f UTF-8 -t BIG5". For example, U+8005 者 occurs twice in - // http://encoding.spec.whatwg.org/index-big5.txt, as index 2148 - // (encoded as "\x8e\xcd") and index 6543 (encoded as "\xaa\xcc") - // and "echo 者 | iconv -f UTF-8 -t BIG5 | xxd" gives "\xaa\xcc". - c0, c1 := x/157, x%157 - if c1 < 0x3f { - c1 += 0x40 - } else { - c1 += 0x62 - } - reverse[y] = (0x81+c0)<<8 | c1 - } - if err := scanner.Err(); err != nil { - log.Fatalf("scanner error: %v", err) - } - - fmt.Printf("// decode is the decoding table from Big5 code to Unicode.\n") - fmt.Printf("// It is defined at http://encoding.spec.whatwg.org/index-big5.txt\n") - fmt.Printf("var decode = [...]uint32{\n") - for i, v := range mapping { - if v != 0 { - fmt.Printf("\t%d: 0x%08X,\n", i, v) - } - } - fmt.Printf("}\n\n") - - // Any run of at least separation continuous zero entries in the reverse map will - // be a separate encode table. - const separation = 1024 - - intervals := []interval(nil) - low, high := -1, -1 - for i, v := range reverse { - if v == 0 { - continue - } - if low < 0 { - low = i - } else if i-high >= separation { - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - low = i - } - high = i + 1 - } - if high >= 0 { - intervals = append(intervals, interval{low, high}) - } - sort.Sort(byDecreasingLength(intervals)) - - fmt.Printf("const numEncodeTables = %d\n\n", len(intervals)) - fmt.Printf("// encodeX are the encoding tables from Unicode to Big5 code,\n") - fmt.Printf("// sorted by decreasing length.\n") - for i, v := range intervals { - fmt.Printf("// encode%d: %5d entries for runes in [%6d, %6d).\n", i, v.len(), v.low, v.high) - } - fmt.Printf("\n") - - for i, v := range intervals { - fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high) - fmt.Printf("var encode%d = [...]uint16{\n", i) - for j := v.low; j < v.high; j++ { - x := reverse[j] - if x == 0 { - continue - } - fmt.Printf("\t%d-%d: 0x%04X,\n", j, v.low, x) - } - fmt.Printf("}\n\n") - } -} - -// interval is a half-open interval [low, high). -type interval struct { - low, high int -} - -func (i interval) len() int { return i.high - i.low } - -// byDecreasingLength sorts intervals by decreasing length. -type byDecreasingLength []interval - -func (b byDecreasingLength) Len() int { return len(b) } -func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() } -func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] } diff --git a/vendor/golang.org/x/text/internal/language/compact/gen.go b/vendor/golang.org/x/text/internal/language/compact/gen.go deleted file mode 100644 index 0c36a052f..000000000 --- a/vendor/golang.org/x/text/internal/language/compact/gen.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Language tag table generator. -// Data read from the web. - -package main - -import ( - "flag" - "fmt" - "log" - - "golang.org/x/text/internal/gen" - "golang.org/x/text/unicode/cldr" -) - -var ( - test = flag.Bool("test", - false, - "test existing tables; can be used to compare web data with package data.") - outputFile = flag.String("output", - "tables.go", - "output file for generated tables") -) - -func main() { - gen.Init() - - w := gen.NewCodeWriter() - defer w.WriteGoFile("tables.go", "compact") - - fmt.Fprintln(w, `import "golang.org/x/text/internal/language"`) - - b := newBuilder(w) - gen.WriteCLDRVersion(w) - - b.writeCompactIndex() -} - -type builder struct { - w *gen.CodeWriter - data *cldr.CLDR - supp *cldr.SupplementalData -} - -func newBuilder(w *gen.CodeWriter) *builder { - r := gen.OpenCLDRCoreZip() - defer r.Close() - d := &cldr.Decoder{} - data, err := d.DecodeZip(r) - if err != nil { - log.Fatal(err) - } - b := builder{ - w: w, - data: data, - supp: data.Supplemental(), - } - return &b -} diff --git a/vendor/golang.org/x/text/internal/language/compact/gen_index.go b/vendor/golang.org/x/text/internal/language/compact/gen_index.go deleted file mode 100644 index 136cefaf0..000000000 --- a/vendor/golang.org/x/text/internal/language/compact/gen_index.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -// This file generates derivative tables based on the language package itself. - -import ( - "fmt" - "log" - "sort" - "strings" - - "golang.org/x/text/internal/language" -) - -// Compact indices: -// Note -va-X variants only apply to localization variants. -// BCP variants only ever apply to language. -// The only ambiguity between tags is with regions. - -func (b *builder) writeCompactIndex() { - // Collect all language tags for which we have any data in CLDR. - m := map[language.Tag]bool{} - for _, lang := range b.data.Locales() { - // We include all locales unconditionally to be consistent with en_US. - // We want en_US, even though it has no data associated with it. - - // TODO: put any of the languages for which no data exists at the end - // of the index. This allows all components based on ICU to use that - // as the cutoff point. - // if x := data.RawLDML(lang); false || - // x.LocaleDisplayNames != nil || - // x.Characters != nil || - // x.Delimiters != nil || - // x.Measurement != nil || - // x.Dates != nil || - // x.Numbers != nil || - // x.Units != nil || - // x.ListPatterns != nil || - // x.Collations != nil || - // x.Segmentations != nil || - // x.Rbnf != nil || - // x.Annotations != nil || - // x.Metadata != nil { - - // TODO: support POSIX natively, albeit non-standard. - tag := language.Make(strings.Replace(lang, "_POSIX", "-u-va-posix", 1)) - m[tag] = true - // } - } - - // TODO: plural rules are also defined for the deprecated tags: - // iw mo sh tl - // Consider removing these as compact tags. - - // Include locales for plural rules, which uses a different structure. - for _, plurals := range b.supp.Plurals { - for _, rules := range plurals.PluralRules { - for _, lang := range strings.Split(rules.Locales, " ") { - m[language.Make(lang)] = true - } - } - } - - var coreTags []language.CompactCoreInfo - var special []string - - for t := range m { - if x := t.Extensions(); len(x) != 0 && fmt.Sprint(x) != "[u-va-posix]" { - log.Fatalf("Unexpected extension %v in %v", x, t) - } - if len(t.Variants()) == 0 && len(t.Extensions()) == 0 { - cci, ok := language.GetCompactCore(t) - if !ok { - log.Fatalf("Locale for non-basic language %q", t) - } - coreTags = append(coreTags, cci) - } else { - special = append(special, t.String()) - } - } - - w := b.w - - sort.Slice(coreTags, func(i, j int) bool { return coreTags[i] < coreTags[j] }) - sort.Strings(special) - - w.WriteComment(` - NumCompactTags is the number of common tags. The maximum tag is - NumCompactTags-1.`) - w.WriteConst("NumCompactTags", len(m)) - - fmt.Fprintln(w, "const (") - for i, t := range coreTags { - fmt.Fprintf(w, "%s ID = %d\n", ident(t.Tag().String()), i) - } - for i, t := range special { - fmt.Fprintf(w, "%s ID = %d\n", ident(t), i+len(coreTags)) - } - fmt.Fprintln(w, ")") - - w.WriteVar("coreTags", coreTags) - - w.WriteConst("specialTagsStr", strings.Join(special, " ")) -} - -func ident(s string) string { - return strings.Replace(s, "-", "", -1) + "Index" -} diff --git a/vendor/golang.org/x/text/internal/language/compact/gen_parents.go b/vendor/golang.org/x/text/internal/language/compact/gen_parents.go deleted file mode 100644 index 9543d5832..000000000 --- a/vendor/golang.org/x/text/internal/language/compact/gen_parents.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2018 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -import ( - "log" - - "golang.org/x/text/internal/gen" - "golang.org/x/text/internal/language" - "golang.org/x/text/internal/language/compact" - "golang.org/x/text/unicode/cldr" -) - -func main() { - r := gen.OpenCLDRCoreZip() - defer r.Close() - - d := &cldr.Decoder{} - data, err := d.DecodeZip(r) - if err != nil { - log.Fatalf("DecodeZip: %v", err) - } - - w := gen.NewCodeWriter() - defer w.WriteGoFile("parents.go", "compact") - - // Create parents table. - type ID uint16 - parents := make([]ID, compact.NumCompactTags) - for _, loc := range data.Locales() { - tag := language.MustParse(loc) - index, ok := compact.FromTag(tag) - if !ok { - continue - } - parentIndex := compact.ID(0) // und - for p := tag.Parent(); p != language.Und; p = p.Parent() { - if x, ok := compact.FromTag(p); ok { - parentIndex = x - break - } - } - parents[index] = ID(parentIndex) - } - - w.WriteComment(` - parents maps a compact index of a tag to the compact index of the parent of - this tag.`) - w.WriteVar("parents", parents) -} diff --git a/vendor/golang.org/x/text/internal/language/gen.go b/vendor/golang.org/x/text/internal/language/gen.go deleted file mode 100644 index cdcc7febc..000000000 --- a/vendor/golang.org/x/text/internal/language/gen.go +++ /dev/null @@ -1,1520 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Language tag table generator. -// Data read from the web. - -package main - -import ( - "bufio" - "flag" - "fmt" - "io" - "io/ioutil" - "log" - "math" - "reflect" - "regexp" - "sort" - "strconv" - "strings" - - "golang.org/x/text/internal/gen" - "golang.org/x/text/internal/tag" - "golang.org/x/text/unicode/cldr" -) - -var ( - test = flag.Bool("test", - false, - "test existing tables; can be used to compare web data with package data.") - outputFile = flag.String("output", - "tables.go", - "output file for generated tables") -) - -var comment = []string{ - ` -lang holds an alphabetically sorted list of ISO-639 language identifiers. -All entries are 4 bytes. The index of the identifier (divided by 4) is the language tag. -For 2-byte language identifiers, the two successive bytes have the following meaning: - - if the first letter of the 2- and 3-letter ISO codes are the same: - the second and third letter of the 3-letter ISO code. - - otherwise: a 0 and a by 2 bits right-shifted index into altLangISO3. -For 3-byte language identifiers the 4th byte is 0.`, - ` -langNoIndex is a bit vector of all 3-letter language codes that are not used as an index -in lookup tables. The language ids for these language codes are derived directly -from the letters and are not consecutive.`, - ` -altLangISO3 holds an alphabetically sorted list of 3-letter language code alternatives -to 2-letter language codes that cannot be derived using the method described above. -Each 3-letter code is followed by its 1-byte langID.`, - ` -altLangIndex is used to convert indexes in altLangISO3 to langIDs.`, - ` -AliasMap maps langIDs to their suggested replacements.`, - ` -script is an alphabetically sorted list of ISO 15924 codes. The index -of the script in the string, divided by 4, is the internal scriptID.`, - ` -isoRegionOffset needs to be added to the index of regionISO to obtain the regionID -for 2-letter ISO codes. (The first isoRegionOffset regionIDs are reserved for -the UN.M49 codes used for groups.)`, - ` -regionISO holds a list of alphabetically sorted 2-letter ISO region codes. -Each 2-letter codes is followed by two bytes with the following meaning: - - [A-Z}{2}: the first letter of the 2-letter code plus these two - letters form the 3-letter ISO code. - - 0, n: index into altRegionISO3.`, - ` -regionTypes defines the status of a region for various standards.`, - ` -m49 maps regionIDs to UN.M49 codes. The first isoRegionOffset entries are -codes indicating collections of regions.`, - ` -m49Index gives indexes into fromM49 based on the three most significant bits -of a 10-bit UN.M49 code. To search an UN.M49 code in fromM49, search in - fromM49[m49Index[msb39(code)]:m49Index[msb3(code)+1]] -for an entry where the first 7 bits match the 7 lsb of the UN.M49 code. -The region code is stored in the 9 lsb of the indexed value.`, - ` -fromM49 contains entries to map UN.M49 codes to regions. See m49Index for details.`, - ` -altRegionISO3 holds a list of 3-letter region codes that cannot be -mapped to 2-letter codes using the default algorithm. This is a short list.`, - ` -altRegionIDs holds a list of regionIDs the positions of which match those -of the 3-letter ISO codes in altRegionISO3.`, - ` -variantNumSpecialized is the number of specialized variants in variants.`, - ` -suppressScript is an index from langID to the dominant script for that language, -if it exists. If a script is given, it should be suppressed from the language tag.`, - ` -likelyLang is a lookup table, indexed by langID, for the most likely -scripts and regions given incomplete information. If more entries exist for a -given language, region and script are the index and size respectively -of the list in likelyLangList.`, - ` -likelyLangList holds lists info associated with likelyLang.`, - ` -likelyRegion is a lookup table, indexed by regionID, for the most likely -languages and scripts given incomplete information. If more entries exist -for a given regionID, lang and script are the index and size respectively -of the list in likelyRegionList. -TODO: exclude containers and user-definable regions from the list.`, - ` -likelyRegionList holds lists info associated with likelyRegion.`, - ` -likelyScript is a lookup table, indexed by scriptID, for the most likely -languages and regions given a script.`, - ` -nRegionGroups is the number of region groups.`, - ` -regionInclusion maps region identifiers to sets of regions in regionInclusionBits, -where each set holds all groupings that are directly connected in a region -containment graph.`, - ` -regionInclusionBits is an array of bit vectors where every vector represents -a set of region groupings. These sets are used to compute the distance -between two regions for the purpose of language matching.`, - ` -regionInclusionNext marks, for each entry in regionInclusionBits, the set of -all groups that are reachable from the groups set in the respective entry.`, -} - -// TODO: consider changing some of these structures to tries. This can reduce -// memory, but may increase the need for memory allocations. This could be -// mitigated if we can piggyback on language tags for common cases. - -func failOnError(e error) { - if e != nil { - log.Panic(e) - } -} - -type setType int - -const ( - Indexed setType = 1 + iota // all elements must be of same size - Linear -) - -type stringSet struct { - s []string - sorted, frozen bool - - // We often need to update values after the creation of an index is completed. - // We include a convenience map for keeping track of this. - update map[string]string - typ setType // used for checking. -} - -func (ss *stringSet) clone() stringSet { - c := *ss - c.s = append([]string(nil), c.s...) - return c -} - -func (ss *stringSet) setType(t setType) { - if ss.typ != t && ss.typ != 0 { - log.Panicf("type %d cannot be assigned as it was already %d", t, ss.typ) - } -} - -// parse parses a whitespace-separated string and initializes ss with its -// components. -func (ss *stringSet) parse(s string) { - scan := bufio.NewScanner(strings.NewReader(s)) - scan.Split(bufio.ScanWords) - for scan.Scan() { - ss.add(scan.Text()) - } -} - -func (ss *stringSet) assertChangeable() { - if ss.frozen { - log.Panic("attempt to modify a frozen stringSet") - } -} - -func (ss *stringSet) add(s string) { - ss.assertChangeable() - ss.s = append(ss.s, s) - ss.sorted = ss.frozen -} - -func (ss *stringSet) freeze() { - ss.compact() - ss.frozen = true -} - -func (ss *stringSet) compact() { - if ss.sorted { - return - } - a := ss.s - sort.Strings(a) - k := 0 - for i := 1; i < len(a); i++ { - if a[k] != a[i] { - a[k+1] = a[i] - k++ - } - } - ss.s = a[:k+1] - ss.sorted = ss.frozen -} - -type funcSorter struct { - fn func(a, b string) bool - sort.StringSlice -} - -func (s funcSorter) Less(i, j int) bool { - return s.fn(s.StringSlice[i], s.StringSlice[j]) -} - -func (ss *stringSet) sortFunc(f func(a, b string) bool) { - ss.compact() - sort.Sort(funcSorter{f, sort.StringSlice(ss.s)}) -} - -func (ss *stringSet) remove(s string) { - ss.assertChangeable() - if i, ok := ss.find(s); ok { - copy(ss.s[i:], ss.s[i+1:]) - ss.s = ss.s[:len(ss.s)-1] - } -} - -func (ss *stringSet) replace(ol, nu string) { - ss.s[ss.index(ol)] = nu - ss.sorted = ss.frozen -} - -func (ss *stringSet) index(s string) int { - ss.setType(Indexed) - i, ok := ss.find(s) - if !ok { - if i < len(ss.s) { - log.Panicf("find: item %q is not in list. Closest match is %q.", s, ss.s[i]) - } - log.Panicf("find: item %q is not in list", s) - - } - return i -} - -func (ss *stringSet) find(s string) (int, bool) { - ss.compact() - i := sort.SearchStrings(ss.s, s) - return i, i != len(ss.s) && ss.s[i] == s -} - -func (ss *stringSet) slice() []string { - ss.compact() - return ss.s -} - -func (ss *stringSet) updateLater(v, key string) { - if ss.update == nil { - ss.update = map[string]string{} - } - ss.update[v] = key -} - -// join joins the string and ensures that all entries are of the same length. -func (ss *stringSet) join() string { - ss.setType(Indexed) - n := len(ss.s[0]) - for _, s := range ss.s { - if len(s) != n { - log.Panicf("join: not all entries are of the same length: %q", s) - } - } - ss.s = append(ss.s, strings.Repeat("\xff", n)) - return strings.Join(ss.s, "") -} - -// ianaEntry holds information for an entry in the IANA Language Subtag Repository. -// All types use the same entry. -// See http://tools.ietf.org/html/bcp47#section-5.1 for a description of the various -// fields. -type ianaEntry struct { - typ string - description []string - scope string - added string - preferred string - deprecated string - suppressScript string - macro string - prefix []string -} - -type builder struct { - w *gen.CodeWriter - hw io.Writer // MultiWriter for w and w.Hash - data *cldr.CLDR - supp *cldr.SupplementalData - - // indices - locale stringSet // common locales - lang stringSet // canonical language ids (2 or 3 letter ISO codes) with data - langNoIndex stringSet // 3-letter ISO codes with no associated data - script stringSet // 4-letter ISO codes - region stringSet // 2-letter ISO or 3-digit UN M49 codes - variant stringSet // 4-8-alphanumeric variant code. - - // Region codes that are groups with their corresponding group IDs. - groups map[int]index - - // langInfo - registry map[string]*ianaEntry -} - -type index uint - -func newBuilder(w *gen.CodeWriter) *builder { - r := gen.OpenCLDRCoreZip() - defer r.Close() - d := &cldr.Decoder{} - data, err := d.DecodeZip(r) - failOnError(err) - b := builder{ - w: w, - hw: io.MultiWriter(w, w.Hash), - data: data, - supp: data.Supplemental(), - } - b.parseRegistry() - return &b -} - -func (b *builder) parseRegistry() { - r := gen.OpenIANAFile("assignments/language-subtag-registry") - defer r.Close() - b.registry = make(map[string]*ianaEntry) - - scan := bufio.NewScanner(r) - scan.Split(bufio.ScanWords) - var record *ianaEntry - for more := scan.Scan(); more; { - key := scan.Text() - more = scan.Scan() - value := scan.Text() - switch key { - case "Type:": - record = &ianaEntry{typ: value} - case "Subtag:", "Tag:": - if s := strings.SplitN(value, "..", 2); len(s) > 1 { - for a := s[0]; a <= s[1]; a = inc(a) { - b.addToRegistry(a, record) - } - } else { - b.addToRegistry(value, record) - } - case "Suppress-Script:": - record.suppressScript = value - case "Added:": - record.added = value - case "Deprecated:": - record.deprecated = value - case "Macrolanguage:": - record.macro = value - case "Preferred-Value:": - record.preferred = value - case "Prefix:": - record.prefix = append(record.prefix, value) - case "Scope:": - record.scope = value - case "Description:": - buf := []byte(value) - for more = scan.Scan(); more; more = scan.Scan() { - b := scan.Bytes() - if b[0] == '%' || b[len(b)-1] == ':' { - break - } - buf = append(buf, ' ') - buf = append(buf, b...) - } - record.description = append(record.description, string(buf)) - continue - default: - continue - } - more = scan.Scan() - } - if scan.Err() != nil { - log.Panic(scan.Err()) - } -} - -func (b *builder) addToRegistry(key string, entry *ianaEntry) { - if info, ok := b.registry[key]; ok { - if info.typ != "language" || entry.typ != "extlang" { - log.Fatalf("parseRegistry: tag %q already exists", key) - } - } else { - b.registry[key] = entry - } -} - -var commentIndex = make(map[string]string) - -func init() { - for _, s := range comment { - key := strings.TrimSpace(strings.SplitN(s, " ", 2)[0]) - commentIndex[key] = s - } -} - -func (b *builder) comment(name string) { - if s := commentIndex[name]; len(s) > 0 { - b.w.WriteComment(s) - } else { - fmt.Fprintln(b.w) - } -} - -func (b *builder) pf(f string, x ...interface{}) { - fmt.Fprintf(b.hw, f, x...) - fmt.Fprint(b.hw, "\n") -} - -func (b *builder) p(x ...interface{}) { - fmt.Fprintln(b.hw, x...) -} - -func (b *builder) addSize(s int) { - b.w.Size += s - b.pf("// Size: %d bytes", s) -} - -func (b *builder) writeConst(name string, x interface{}) { - b.comment(name) - b.w.WriteConst(name, x) -} - -// writeConsts computes f(v) for all v in values and writes the results -// as constants named _v to a single constant block. -func (b *builder) writeConsts(f func(string) int, values ...string) { - b.pf("const (") - for _, v := range values { - b.pf("\t_%s = %v", v, f(v)) - } - b.pf(")") -} - -// writeType writes the type of the given value, which must be a struct. -func (b *builder) writeType(value interface{}) { - b.comment(reflect.TypeOf(value).Name()) - b.w.WriteType(value) -} - -func (b *builder) writeSlice(name string, ss interface{}) { - b.writeSliceAddSize(name, 0, ss) -} - -func (b *builder) writeSliceAddSize(name string, extraSize int, ss interface{}) { - b.comment(name) - b.w.Size += extraSize - v := reflect.ValueOf(ss) - t := v.Type().Elem() - b.pf("// Size: %d bytes, %d elements", v.Len()*int(t.Size())+extraSize, v.Len()) - - fmt.Fprintf(b.w, "var %s = ", name) - b.w.WriteArray(ss) - b.p() -} - -type FromTo struct { - From, To uint16 -} - -func (b *builder) writeSortedMap(name string, ss *stringSet, index func(s string) uint16) { - ss.sortFunc(func(a, b string) bool { - return index(a) < index(b) - }) - m := []FromTo{} - for _, s := range ss.s { - m = append(m, FromTo{index(s), index(ss.update[s])}) - } - b.writeSlice(name, m) -} - -const base = 'z' - 'a' + 1 - -func strToInt(s string) uint { - v := uint(0) - for i := 0; i < len(s); i++ { - v *= base - v += uint(s[i] - 'a') - } - return v -} - -// converts the given integer to the original ASCII string passed to strToInt. -// len(s) must match the number of characters obtained. -func intToStr(v uint, s []byte) { - for i := len(s) - 1; i >= 0; i-- { - s[i] = byte(v%base) + 'a' - v /= base - } -} - -func (b *builder) writeBitVector(name string, ss []string) { - vec := make([]uint8, int(math.Ceil(math.Pow(base, float64(len(ss[0])))/8))) - for _, s := range ss { - v := strToInt(s) - vec[v/8] |= 1 << (v % 8) - } - b.writeSlice(name, vec) -} - -// TODO: convert this type into a list or two-stage trie. -func (b *builder) writeMapFunc(name string, m map[string]string, f func(string) uint16) { - b.comment(name) - v := reflect.ValueOf(m) - sz := v.Len() * (2 + int(v.Type().Key().Size())) - for _, k := range m { - sz += len(k) - } - b.addSize(sz) - keys := []string{} - b.pf(`var %s = map[string]uint16{`, name) - for k := range m { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - b.pf("\t%q: %v,", k, f(m[k])) - } - b.p("}") -} - -func (b *builder) writeMap(name string, m interface{}) { - b.comment(name) - v := reflect.ValueOf(m) - sz := v.Len() * (2 + int(v.Type().Key().Size()) + int(v.Type().Elem().Size())) - b.addSize(sz) - f := strings.FieldsFunc(fmt.Sprintf("%#v", m), func(r rune) bool { - return strings.IndexRune("{}, ", r) != -1 - }) - sort.Strings(f[1:]) - b.pf(`var %s = %s{`, name, f[0]) - for _, kv := range f[1:] { - b.pf("\t%s,", kv) - } - b.p("}") -} - -func (b *builder) langIndex(s string) uint16 { - if s == "und" { - return 0 - } - if i, ok := b.lang.find(s); ok { - return uint16(i) - } - return uint16(strToInt(s)) + uint16(len(b.lang.s)) -} - -// inc advances the string to its lexicographical successor. -func inc(s string) string { - const maxTagLength = 4 - var buf [maxTagLength]byte - intToStr(strToInt(strings.ToLower(s))+1, buf[:len(s)]) - for i := 0; i < len(s); i++ { - if s[i] <= 'Z' { - buf[i] -= 'a' - 'A' - } - } - return string(buf[:len(s)]) -} - -func (b *builder) parseIndices() { - meta := b.supp.Metadata - - for k, v := range b.registry { - var ss *stringSet - switch v.typ { - case "language": - if len(k) == 2 || v.suppressScript != "" || v.scope == "special" { - b.lang.add(k) - continue - } else { - ss = &b.langNoIndex - } - case "region": - ss = &b.region - case "script": - ss = &b.script - case "variant": - ss = &b.variant - default: - continue - } - ss.add(k) - } - // Include any language for which there is data. - for _, lang := range b.data.Locales() { - if x := b.data.RawLDML(lang); false || - x.LocaleDisplayNames != nil || - x.Characters != nil || - x.Delimiters != nil || - x.Measurement != nil || - x.Dates != nil || - x.Numbers != nil || - x.Units != nil || - x.ListPatterns != nil || - x.Collations != nil || - x.Segmentations != nil || - x.Rbnf != nil || - x.Annotations != nil || - x.Metadata != nil { - - from := strings.Split(lang, "_") - if lang := from[0]; lang != "root" { - b.lang.add(lang) - } - } - } - // Include locales for plural rules, which uses a different structure. - for _, plurals := range b.data.Supplemental().Plurals { - for _, rules := range plurals.PluralRules { - for _, lang := range strings.Split(rules.Locales, " ") { - if lang = strings.Split(lang, "_")[0]; lang != "root" { - b.lang.add(lang) - } - } - } - } - // Include languages in likely subtags. - for _, m := range b.supp.LikelySubtags.LikelySubtag { - from := strings.Split(m.From, "_") - b.lang.add(from[0]) - } - // Include ISO-639 alpha-3 bibliographic entries. - for _, a := range meta.Alias.LanguageAlias { - if a.Reason == "bibliographic" { - b.langNoIndex.add(a.Type) - } - } - // Include regions in territoryAlias (not all are in the IANA registry!) - for _, reg := range b.supp.Metadata.Alias.TerritoryAlias { - if len(reg.Type) == 2 { - b.region.add(reg.Type) - } - } - - for _, s := range b.lang.s { - if len(s) == 3 { - b.langNoIndex.remove(s) - } - } - b.writeConst("NumLanguages", len(b.lang.slice())+len(b.langNoIndex.slice())) - b.writeConst("NumScripts", len(b.script.slice())) - b.writeConst("NumRegions", len(b.region.slice())) - - // Add dummy codes at the start of each list to represent "unspecified". - b.lang.add("---") - b.script.add("----") - b.region.add("---") - - // common locales - b.locale.parse(meta.DefaultContent.Locales) -} - -// TODO: region inclusion data will probably not be use used in future matchers. - -func (b *builder) computeRegionGroups() { - b.groups = make(map[int]index) - - // Create group indices. - for i := 1; b.region.s[i][0] < 'A'; i++ { // Base M49 indices on regionID. - b.groups[i] = index(len(b.groups)) - } - for _, g := range b.supp.TerritoryContainment.Group { - // Skip UN and EURO zone as they are flattening the containment - // relationship. - if g.Type == "EZ" || g.Type == "UN" { - continue - } - group := b.region.index(g.Type) - if _, ok := b.groups[group]; !ok { - b.groups[group] = index(len(b.groups)) - } - } - if len(b.groups) > 64 { - log.Fatalf("only 64 groups supported, found %d", len(b.groups)) - } - b.writeConst("nRegionGroups", len(b.groups)) -} - -var langConsts = []string{ - "af", "am", "ar", "az", "bg", "bn", "ca", "cs", "da", "de", "el", "en", "es", - "et", "fa", "fi", "fil", "fr", "gu", "he", "hi", "hr", "hu", "hy", "id", "is", - "it", "ja", "ka", "kk", "km", "kn", "ko", "ky", "lo", "lt", "lv", "mk", "ml", - "mn", "mo", "mr", "ms", "mul", "my", "nb", "ne", "nl", "no", "pa", "pl", "pt", - "ro", "ru", "sh", "si", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", - "tl", "tn", "tr", "uk", "ur", "uz", "vi", "zh", "zu", - - // constants for grandfathered tags (if not already defined) - "jbo", "ami", "bnn", "hak", "tlh", "lb", "nv", "pwn", "tao", "tay", "tsu", - "nn", "sfb", "vgt", "sgg", "cmn", "nan", "hsn", -} - -// writeLanguage generates all tables needed for language canonicalization. -func (b *builder) writeLanguage() { - meta := b.supp.Metadata - - b.writeConst("nonCanonicalUnd", b.lang.index("und")) - b.writeConsts(func(s string) int { return int(b.langIndex(s)) }, langConsts...) - b.writeConst("langPrivateStart", b.langIndex("qaa")) - b.writeConst("langPrivateEnd", b.langIndex("qtz")) - - // Get language codes that need to be mapped (overlong 3-letter codes, - // deprecated 2-letter codes, legacy and grandfathered tags.) - langAliasMap := stringSet{} - aliasTypeMap := map[string]AliasType{} - - // altLangISO3 get the alternative ISO3 names that need to be mapped. - altLangISO3 := stringSet{} - // Add dummy start to avoid the use of index 0. - altLangISO3.add("---") - altLangISO3.updateLater("---", "aa") - - lang := b.lang.clone() - for _, a := range meta.Alias.LanguageAlias { - if a.Replacement == "" { - a.Replacement = "und" - } - // TODO: support mapping to tags - repl := strings.SplitN(a.Replacement, "_", 2)[0] - if a.Reason == "overlong" { - if len(a.Replacement) == 2 && len(a.Type) == 3 { - lang.updateLater(a.Replacement, a.Type) - } - } else if len(a.Type) <= 3 { - switch a.Reason { - case "macrolanguage": - aliasTypeMap[a.Type] = Macro - case "deprecated": - // handled elsewhere - continue - case "bibliographic", "legacy": - if a.Type == "no" { - continue - } - aliasTypeMap[a.Type] = Legacy - default: - log.Fatalf("new %s alias: %s", a.Reason, a.Type) - } - langAliasMap.add(a.Type) - langAliasMap.updateLater(a.Type, repl) - } - } - // Manually add the mapping of "nb" (Norwegian) to its macro language. - // This can be removed if CLDR adopts this change. - langAliasMap.add("nb") - langAliasMap.updateLater("nb", "no") - aliasTypeMap["nb"] = Macro - - for k, v := range b.registry { - // Also add deprecated values for 3-letter ISO codes, which CLDR omits. - if v.typ == "language" && v.deprecated != "" && v.preferred != "" { - langAliasMap.add(k) - langAliasMap.updateLater(k, v.preferred) - aliasTypeMap[k] = Deprecated - } - } - // Fix CLDR mappings. - lang.updateLater("tl", "tgl") - lang.updateLater("sh", "hbs") - lang.updateLater("mo", "mol") - lang.updateLater("no", "nor") - lang.updateLater("tw", "twi") - lang.updateLater("nb", "nob") - lang.updateLater("ak", "aka") - lang.updateLater("bh", "bih") - - // Ensure that each 2-letter code is matched with a 3-letter code. - for _, v := range lang.s[1:] { - s, ok := lang.update[v] - if !ok { - if s, ok = lang.update[langAliasMap.update[v]]; !ok { - continue - } - lang.update[v] = s - } - if v[0] != s[0] { - altLangISO3.add(s) - altLangISO3.updateLater(s, v) - } - } - - // Complete canonicalized language tags. - lang.freeze() - for i, v := range lang.s { - // We can avoid these manual entries by using the IANA registry directly. - // Seems easier to update the list manually, as changes are rare. - // The panic in this loop will trigger if we miss an entry. - add := "" - if s, ok := lang.update[v]; ok { - if s[0] == v[0] { - add = s[1:] - } else { - add = string([]byte{0, byte(altLangISO3.index(s))}) - } - } else if len(v) == 3 { - add = "\x00" - } else { - log.Panicf("no data for long form of %q", v) - } - lang.s[i] += add - } - b.writeConst("lang", tag.Index(lang.join())) - - b.writeConst("langNoIndexOffset", len(b.lang.s)) - - // space of all valid 3-letter language identifiers. - b.writeBitVector("langNoIndex", b.langNoIndex.slice()) - - altLangIndex := []uint16{} - for i, s := range altLangISO3.slice() { - altLangISO3.s[i] += string([]byte{byte(len(altLangIndex))}) - if i > 0 { - idx := b.lang.index(altLangISO3.update[s]) - altLangIndex = append(altLangIndex, uint16(idx)) - } - } - b.writeConst("altLangISO3", tag.Index(altLangISO3.join())) - b.writeSlice("altLangIndex", altLangIndex) - - b.writeSortedMap("AliasMap", &langAliasMap, b.langIndex) - types := make([]AliasType, len(langAliasMap.s)) - for i, s := range langAliasMap.s { - types[i] = aliasTypeMap[s] - } - b.writeSlice("AliasTypes", types) -} - -var scriptConsts = []string{ - "Latn", "Hani", "Hans", "Hant", "Qaaa", "Qaai", "Qabx", "Zinh", "Zyyy", - "Zzzz", -} - -func (b *builder) writeScript() { - b.writeConsts(b.script.index, scriptConsts...) - b.writeConst("script", tag.Index(b.script.join())) - - supp := make([]uint8, len(b.lang.slice())) - for i, v := range b.lang.slice()[1:] { - if sc := b.registry[v].suppressScript; sc != "" { - supp[i+1] = uint8(b.script.index(sc)) - } - } - b.writeSlice("suppressScript", supp) - - // There is only one deprecated script in CLDR. This value is hard-coded. - // We check here if the code must be updated. - for _, a := range b.supp.Metadata.Alias.ScriptAlias { - if a.Type != "Qaai" { - log.Panicf("unexpected deprecated stript %q", a.Type) - } - } -} - -func parseM49(s string) int16 { - if len(s) == 0 { - return 0 - } - v, err := strconv.ParseUint(s, 10, 10) - failOnError(err) - return int16(v) -} - -var regionConsts = []string{ - "001", "419", "BR", "CA", "ES", "GB", "MD", "PT", "UK", "US", - "ZZ", "XA", "XC", "XK", // Unofficial tag for Kosovo. -} - -func (b *builder) writeRegion() { - b.writeConsts(b.region.index, regionConsts...) - - isoOffset := b.region.index("AA") - m49map := make([]int16, len(b.region.slice())) - fromM49map := make(map[int16]int) - altRegionISO3 := "" - altRegionIDs := []uint16{} - - b.writeConst("isoRegionOffset", isoOffset) - - // 2-letter region lookup and mapping to numeric codes. - regionISO := b.region.clone() - regionISO.s = regionISO.s[isoOffset:] - regionISO.sorted = false - - regionTypes := make([]byte, len(b.region.s)) - - // Is the region valid BCP 47? - for s, e := range b.registry { - if len(s) == 2 && s == strings.ToUpper(s) { - i := b.region.index(s) - for _, d := range e.description { - if strings.Contains(d, "Private use") { - regionTypes[i] = iso3166UserAssigned - } - } - regionTypes[i] |= bcp47Region - } - } - - // Is the region a valid ccTLD? - r := gen.OpenIANAFile("domains/root/db") - defer r.Close() - - buf, err := ioutil.ReadAll(r) - failOnError(err) - re := regexp.MustCompile(`"/domains/root/db/([a-z]{2}).html"`) - for _, m := range re.FindAllSubmatch(buf, -1) { - i := b.region.index(strings.ToUpper(string(m[1]))) - regionTypes[i] |= ccTLD - } - - b.writeSlice("regionTypes", regionTypes) - - iso3Set := make(map[string]int) - update := func(iso2, iso3 string) { - i := regionISO.index(iso2) - if j, ok := iso3Set[iso3]; !ok && iso3[0] == iso2[0] { - regionISO.s[i] += iso3[1:] - iso3Set[iso3] = -1 - } else { - if ok && j >= 0 { - regionISO.s[i] += string([]byte{0, byte(j)}) - } else { - iso3Set[iso3] = len(altRegionISO3) - regionISO.s[i] += string([]byte{0, byte(len(altRegionISO3))}) - altRegionISO3 += iso3 - altRegionIDs = append(altRegionIDs, uint16(isoOffset+i)) - } - } - } - for _, tc := range b.supp.CodeMappings.TerritoryCodes { - i := regionISO.index(tc.Type) + isoOffset - if d := m49map[i]; d != 0 { - log.Panicf("%s found as a duplicate UN.M49 code of %03d", tc.Numeric, d) - } - m49 := parseM49(tc.Numeric) - m49map[i] = m49 - if r := fromM49map[m49]; r == 0 { - fromM49map[m49] = i - } else if r != i { - dep := b.registry[regionISO.s[r-isoOffset]].deprecated - if t := b.registry[tc.Type]; t != nil && dep != "" && (t.deprecated == "" || t.deprecated > dep) { - fromM49map[m49] = i - } - } - } - for _, ta := range b.supp.Metadata.Alias.TerritoryAlias { - if len(ta.Type) == 3 && ta.Type[0] <= '9' && len(ta.Replacement) == 2 { - from := parseM49(ta.Type) - if r := fromM49map[from]; r == 0 { - fromM49map[from] = regionISO.index(ta.Replacement) + isoOffset - } - } - } - for _, tc := range b.supp.CodeMappings.TerritoryCodes { - if len(tc.Alpha3) == 3 { - update(tc.Type, tc.Alpha3) - } - } - // This entries are not included in territoryCodes. Mostly 3-letter variants - // of deleted codes and an entry for QU. - for _, m := range []struct{ iso2, iso3 string }{ - {"CT", "CTE"}, - {"DY", "DHY"}, - {"HV", "HVO"}, - {"JT", "JTN"}, - {"MI", "MID"}, - {"NH", "NHB"}, - {"NQ", "ATN"}, - {"PC", "PCI"}, - {"PU", "PUS"}, - {"PZ", "PCZ"}, - {"RH", "RHO"}, - {"VD", "VDR"}, - {"WK", "WAK"}, - // These three-letter codes are used for others as well. - {"FQ", "ATF"}, - } { - update(m.iso2, m.iso3) - } - for i, s := range regionISO.s { - if len(s) != 4 { - regionISO.s[i] = s + " " - } - } - b.writeConst("regionISO", tag.Index(regionISO.join())) - b.writeConst("altRegionISO3", altRegionISO3) - b.writeSlice("altRegionIDs", altRegionIDs) - - // Create list of deprecated regions. - // TODO: consider inserting SF -> FI. Not included by CLDR, but is the only - // Transitionally-reserved mapping not included. - regionOldMap := stringSet{} - // Include regions in territoryAlias (not all are in the IANA registry!) - for _, reg := range b.supp.Metadata.Alias.TerritoryAlias { - if len(reg.Type) == 2 && reg.Reason == "deprecated" && len(reg.Replacement) == 2 { - regionOldMap.add(reg.Type) - regionOldMap.updateLater(reg.Type, reg.Replacement) - i, _ := regionISO.find(reg.Type) - j, _ := regionISO.find(reg.Replacement) - if k := m49map[i+isoOffset]; k == 0 { - m49map[i+isoOffset] = m49map[j+isoOffset] - } - } - } - b.writeSortedMap("regionOldMap", ®ionOldMap, func(s string) uint16 { - return uint16(b.region.index(s)) - }) - // 3-digit region lookup, groupings. - for i := 1; i < isoOffset; i++ { - m := parseM49(b.region.s[i]) - m49map[i] = m - fromM49map[m] = i - } - b.writeSlice("m49", m49map) - - const ( - searchBits = 7 - regionBits = 9 - ) - if len(m49map) >= 1< %d", len(m49map), 1<>searchBits] = int16(len(fromM49)) - } - b.writeSlice("m49Index", m49Index) - b.writeSlice("fromM49", fromM49) -} - -const ( - // TODO: put these lists in regionTypes as user data? Could be used for - // various optimizations and refinements and could be exposed in the API. - iso3166Except = "AC CP DG EA EU FX IC SU TA UK" - iso3166Trans = "AN BU CS NT TP YU ZR" // SF is not in our set of Regions. - // DY and RH are actually not deleted, but indeterminately reserved. - iso3166DelCLDR = "CT DD DY FQ HV JT MI NH NQ PC PU PZ RH VD WK YD" -) - -const ( - iso3166UserAssigned = 1 << iota - ccTLD - bcp47Region -) - -func find(list []string, s string) int { - for i, t := range list { - if t == s { - return i - } - } - return -1 -} - -// writeVariants generates per-variant information and creates a map from variant -// name to index value. We assign index values such that sorting multiple -// variants by index value will result in the correct order. -// There are two types of variants: specialized and general. Specialized variants -// are only applicable to certain language or language-script pairs. Generalized -// variants apply to any language. Generalized variants always sort after -// specialized variants. We will therefore always assign a higher index value -// to a generalized variant than any other variant. Generalized variants are -// sorted alphabetically among themselves. -// Specialized variants may also sort after other specialized variants. Such -// variants will be ordered after any of the variants they may follow. -// We assume that if a variant x is followed by a variant y, then for any prefix -// p of x, p-x is a prefix of y. This allows us to order tags based on the -// maximum of the length of any of its prefixes. -// TODO: it is possible to define a set of Prefix values on variants such that -// a total order cannot be defined to the point that this algorithm breaks. -// In other words, we cannot guarantee the same order of variants for the -// future using the same algorithm or for non-compliant combinations of -// variants. For this reason, consider using simple alphabetic sorting -// of variants and ignore Prefix restrictions altogether. -func (b *builder) writeVariant() { - generalized := stringSet{} - specialized := stringSet{} - specializedExtend := stringSet{} - // Collate the variants by type and check assumptions. - for _, v := range b.variant.slice() { - e := b.registry[v] - if len(e.prefix) == 0 { - generalized.add(v) - continue - } - c := strings.Split(e.prefix[0], "-") - hasScriptOrRegion := false - if len(c) > 1 { - _, hasScriptOrRegion = b.script.find(c[1]) - if !hasScriptOrRegion { - _, hasScriptOrRegion = b.region.find(c[1]) - - } - } - if len(c) == 1 || len(c) == 2 && hasScriptOrRegion { - // Variant is preceded by a language. - specialized.add(v) - continue - } - // Variant is preceded by another variant. - specializedExtend.add(v) - prefix := c[0] + "-" - if hasScriptOrRegion { - prefix += c[1] - } - for _, p := range e.prefix { - // Verify that the prefix minus the last element is a prefix of the - // predecessor element. - i := strings.LastIndex(p, "-") - pred := b.registry[p[i+1:]] - if find(pred.prefix, p[:i]) < 0 { - log.Fatalf("prefix %q for variant %q not consistent with predecessor spec", p, v) - } - // The sorting used below does not work in the general case. It works - // if we assume that variants that may be followed by others only have - // prefixes of the same length. Verify this. - count := strings.Count(p[:i], "-") - for _, q := range pred.prefix { - if c := strings.Count(q, "-"); c != count { - log.Fatalf("variant %q preceding %q has a prefix %q of size %d; want %d", p[i+1:], v, q, c, count) - } - } - if !strings.HasPrefix(p, prefix) { - log.Fatalf("prefix %q of variant %q should start with %q", p, v, prefix) - } - } - } - - // Sort extended variants. - a := specializedExtend.s - less := func(v, w string) bool { - // Sort by the maximum number of elements. - maxCount := func(s string) (max int) { - for _, p := range b.registry[s].prefix { - if c := strings.Count(p, "-"); c > max { - max = c - } - } - return - } - if cv, cw := maxCount(v), maxCount(w); cv != cw { - return cv < cw - } - // Sort by name as tie breaker. - return v < w - } - sort.Sort(funcSorter{less, sort.StringSlice(a)}) - specializedExtend.frozen = true - - // Create index from variant name to index. - variantIndex := make(map[string]uint8) - add := func(s []string) { - for _, v := range s { - variantIndex[v] = uint8(len(variantIndex)) - } - } - add(specialized.slice()) - add(specializedExtend.s) - numSpecialized := len(variantIndex) - add(generalized.slice()) - if n := len(variantIndex); n > 255 { - log.Fatalf("maximum number of variants exceeded: was %d; want <= 255", n) - } - b.writeMap("variantIndex", variantIndex) - b.writeConst("variantNumSpecialized", numSpecialized) -} - -func (b *builder) writeLanguageInfo() { -} - -// writeLikelyData writes tables that are used both for finding parent relations and for -// language matching. Each entry contains additional bits to indicate the status of the -// data to know when it cannot be used for parent relations. -func (b *builder) writeLikelyData() { - const ( - isList = 1 << iota - scriptInFrom - regionInFrom - ) - type ( // generated types - likelyScriptRegion struct { - region uint16 - script uint8 - flags uint8 - } - likelyLangScript struct { - lang uint16 - script uint8 - flags uint8 - } - likelyLangRegion struct { - lang uint16 - region uint16 - } - // likelyTag is used for getting likely tags for group regions, where - // the likely region might be a region contained in the group. - likelyTag struct { - lang uint16 - region uint16 - script uint8 - } - ) - var ( // generated variables - likelyRegionGroup = make([]likelyTag, len(b.groups)) - likelyLang = make([]likelyScriptRegion, len(b.lang.s)) - likelyRegion = make([]likelyLangScript, len(b.region.s)) - likelyScript = make([]likelyLangRegion, len(b.script.s)) - likelyLangList = []likelyScriptRegion{} - likelyRegionList = []likelyLangScript{} - ) - type fromTo struct { - from, to []string - } - langToOther := map[int][]fromTo{} - regionToOther := map[int][]fromTo{} - for _, m := range b.supp.LikelySubtags.LikelySubtag { - from := strings.Split(m.From, "_") - to := strings.Split(m.To, "_") - if len(to) != 3 { - log.Fatalf("invalid number of subtags in %q: found %d, want 3", m.To, len(to)) - } - if len(from) > 3 { - log.Fatalf("invalid number of subtags: found %d, want 1-3", len(from)) - } - if from[0] != to[0] && from[0] != "und" { - log.Fatalf("unexpected language change in expansion: %s -> %s", from, to) - } - if len(from) == 3 { - if from[2] != to[2] { - log.Fatalf("unexpected region change in expansion: %s -> %s", from, to) - } - if from[0] != "und" { - log.Fatalf("unexpected fully specified from tag: %s -> %s", from, to) - } - } - if len(from) == 1 || from[0] != "und" { - id := 0 - if from[0] != "und" { - id = b.lang.index(from[0]) - } - langToOther[id] = append(langToOther[id], fromTo{from, to}) - } else if len(from) == 2 && len(from[1]) == 4 { - sid := b.script.index(from[1]) - likelyScript[sid].lang = uint16(b.langIndex(to[0])) - likelyScript[sid].region = uint16(b.region.index(to[2])) - } else { - r := b.region.index(from[len(from)-1]) - if id, ok := b.groups[r]; ok { - if from[0] != "und" { - log.Fatalf("region changed unexpectedly: %s -> %s", from, to) - } - likelyRegionGroup[id].lang = uint16(b.langIndex(to[0])) - likelyRegionGroup[id].script = uint8(b.script.index(to[1])) - likelyRegionGroup[id].region = uint16(b.region.index(to[2])) - } else { - regionToOther[r] = append(regionToOther[r], fromTo{from, to}) - } - } - } - b.writeType(likelyLangRegion{}) - b.writeSlice("likelyScript", likelyScript) - - for id := range b.lang.s { - list := langToOther[id] - if len(list) == 1 { - likelyLang[id].region = uint16(b.region.index(list[0].to[2])) - likelyLang[id].script = uint8(b.script.index(list[0].to[1])) - } else if len(list) > 1 { - likelyLang[id].flags = isList - likelyLang[id].region = uint16(len(likelyLangList)) - likelyLang[id].script = uint8(len(list)) - for _, x := range list { - flags := uint8(0) - if len(x.from) > 1 { - if x.from[1] == x.to[2] { - flags = regionInFrom - } else { - flags = scriptInFrom - } - } - likelyLangList = append(likelyLangList, likelyScriptRegion{ - region: uint16(b.region.index(x.to[2])), - script: uint8(b.script.index(x.to[1])), - flags: flags, - }) - } - } - } - // TODO: merge suppressScript data with this table. - b.writeType(likelyScriptRegion{}) - b.writeSlice("likelyLang", likelyLang) - b.writeSlice("likelyLangList", likelyLangList) - - for id := range b.region.s { - list := regionToOther[id] - if len(list) == 1 { - likelyRegion[id].lang = uint16(b.langIndex(list[0].to[0])) - likelyRegion[id].script = uint8(b.script.index(list[0].to[1])) - if len(list[0].from) > 2 { - likelyRegion[id].flags = scriptInFrom - } - } else if len(list) > 1 { - likelyRegion[id].flags = isList - likelyRegion[id].lang = uint16(len(likelyRegionList)) - likelyRegion[id].script = uint8(len(list)) - for i, x := range list { - if len(x.from) == 2 && i != 0 || i > 0 && len(x.from) != 3 { - log.Fatalf("unspecified script must be first in list: %v at %d", x.from, i) - } - x := likelyLangScript{ - lang: uint16(b.langIndex(x.to[0])), - script: uint8(b.script.index(x.to[1])), - } - if len(list[0].from) > 2 { - x.flags = scriptInFrom - } - likelyRegionList = append(likelyRegionList, x) - } - } - } - b.writeType(likelyLangScript{}) - b.writeSlice("likelyRegion", likelyRegion) - b.writeSlice("likelyRegionList", likelyRegionList) - - b.writeType(likelyTag{}) - b.writeSlice("likelyRegionGroup", likelyRegionGroup) -} - -func (b *builder) writeRegionInclusionData() { - var ( - // mm holds for each group the set of groups with a distance of 1. - mm = make(map[int][]index) - - // containment holds for each group the transitive closure of - // containment of other groups. - containment = make(map[index][]index) - ) - for _, g := range b.supp.TerritoryContainment.Group { - // Skip UN and EURO zone as they are flattening the containment - // relationship. - if g.Type == "EZ" || g.Type == "UN" { - continue - } - group := b.region.index(g.Type) - groupIdx := b.groups[group] - for _, mem := range strings.Split(g.Contains, " ") { - r := b.region.index(mem) - mm[r] = append(mm[r], groupIdx) - if g, ok := b.groups[r]; ok { - mm[group] = append(mm[group], g) - containment[groupIdx] = append(containment[groupIdx], g) - } - } - } - - regionContainment := make([]uint64, len(b.groups)) - for _, g := range b.groups { - l := containment[g] - - // Compute the transitive closure of containment. - for i := 0; i < len(l); i++ { - l = append(l, containment[l[i]]...) - } - - // Compute the bitmask. - regionContainment[g] = 1 << g - for _, v := range l { - regionContainment[g] |= 1 << v - } - } - b.writeSlice("regionContainment", regionContainment) - - regionInclusion := make([]uint8, len(b.region.s)) - bvs := make(map[uint64]index) - // Make the first bitvector positions correspond with the groups. - for r, i := range b.groups { - bv := uint64(1 << i) - for _, g := range mm[r] { - bv |= 1 << g - } - bvs[bv] = i - regionInclusion[r] = uint8(bvs[bv]) - } - for r := 1; r < len(b.region.s); r++ { - if _, ok := b.groups[r]; !ok { - bv := uint64(0) - for _, g := range mm[r] { - bv |= 1 << g - } - if bv == 0 { - // Pick the world for unspecified regions. - bv = 1 << b.groups[b.region.index("001")] - } - if _, ok := bvs[bv]; !ok { - bvs[bv] = index(len(bvs)) - } - regionInclusion[r] = uint8(bvs[bv]) - } - } - b.writeSlice("regionInclusion", regionInclusion) - regionInclusionBits := make([]uint64, len(bvs)) - for k, v := range bvs { - regionInclusionBits[v] = uint64(k) - } - // Add bit vectors for increasingly large distances until a fixed point is reached. - regionInclusionNext := []uint8{} - for i := 0; i < len(regionInclusionBits); i++ { - bits := regionInclusionBits[i] - next := bits - for i := uint(0); i < uint(len(b.groups)); i++ { - if bits&(1< 6 { - log.Fatalf("Too many groups: %d", i) - } - idToIndex[mv.Id] = uint8(i + 1) - // TODO: also handle '-' - for _, r := range strings.Split(mv.Value, "+") { - todo := []string{r} - for k := 0; k < len(todo); k++ { - r := todo[k] - regionToGroups[b.regionIndex(r)] |= 1 << uint8(i) - todo = append(todo, regionHierarchy[r]...) - } - } - } - b.w.WriteVar("regionToGroups", regionToGroups) - - // maps language id to in- and out-of-group region. - paradigmLocales := [][3]uint16{} - locales := strings.Split(lm[0].ParadigmLocales[0].Locales, " ") - for i := 0; i < len(locales); i += 2 { - x := [3]uint16{} - for j := 0; j < 2; j++ { - pc := strings.SplitN(locales[i+j], "-", 2) - x[0] = b.langIndex(pc[0]) - if len(pc) == 2 { - x[1+j] = uint16(b.regionIndex(pc[1])) - } - } - paradigmLocales = append(paradigmLocales, x) - } - b.w.WriteVar("paradigmLocales", paradigmLocales) - - b.w.WriteType(mutualIntelligibility{}) - b.w.WriteType(scriptIntelligibility{}) - b.w.WriteType(regionIntelligibility{}) - - matchLang := []mutualIntelligibility{} - matchScript := []scriptIntelligibility{} - matchRegion := []regionIntelligibility{} - // Convert the languageMatch entries in lists keyed by desired language. - for _, m := range lm[0].LanguageMatch { - // Different versions of CLDR use different separators. - desired := strings.Replace(m.Desired, "-", "_", -1) - supported := strings.Replace(m.Supported, "-", "_", -1) - d := strings.Split(desired, "_") - s := strings.Split(supported, "_") - if len(d) != len(s) { - log.Fatalf("not supported: desired=%q; supported=%q", desired, supported) - continue - } - distance, _ := strconv.ParseInt(m.Distance, 10, 8) - switch len(d) { - case 2: - if desired == supported && desired == "*_*" { - continue - } - // language-script pair. - matchScript = append(matchScript, scriptIntelligibility{ - wantLang: uint16(b.langIndex(d[0])), - haveLang: uint16(b.langIndex(s[0])), - wantScript: uint8(b.scriptIndex(d[1])), - haveScript: uint8(b.scriptIndex(s[1])), - distance: uint8(distance), - }) - if m.Oneway != "true" { - matchScript = append(matchScript, scriptIntelligibility{ - wantLang: uint16(b.langIndex(s[0])), - haveLang: uint16(b.langIndex(d[0])), - wantScript: uint8(b.scriptIndex(s[1])), - haveScript: uint8(b.scriptIndex(d[1])), - distance: uint8(distance), - }) - } - case 1: - if desired == supported && desired == "*" { - continue - } - if distance == 1 { - // nb == no is already handled by macro mapping. Check there - // really is only this case. - if d[0] != "no" || s[0] != "nb" { - log.Fatalf("unhandled equivalence %s == %s", s[0], d[0]) - } - continue - } - // TODO: consider dropping oneway field and just doubling the entry. - matchLang = append(matchLang, mutualIntelligibility{ - want: uint16(b.langIndex(d[0])), - have: uint16(b.langIndex(s[0])), - distance: uint8(distance), - oneway: m.Oneway == "true", - }) - case 3: - if desired == supported && desired == "*_*_*" { - continue - } - if desired != supported { - // This is now supported by CLDR, but only one case, which - // should already be covered by paradigm locales. For instance, - // test case "und, en, en-GU, en-IN, en-GB ; en-ZA ; en-GB" in - // testdata/CLDRLocaleMatcherTest.txt tests this. - if supported != "en_*_GB" { - log.Fatalf("not supported: desired=%q; supported=%q", desired, supported) - } - continue - } - ri := regionIntelligibility{ - lang: b.langIndex(d[0]), - distance: uint8(distance), - } - if d[1] != "*" { - ri.script = uint8(b.scriptIndex(d[1])) - } - switch { - case d[2] == "*": - ri.group = 0x80 // not contained in anything - case strings.HasPrefix(d[2], "$!"): - ri.group = 0x80 - d[2] = "$" + d[2][len("$!"):] - fallthrough - case strings.HasPrefix(d[2], "$"): - ri.group |= idToIndex[d[2]] - } - matchRegion = append(matchRegion, ri) - default: - log.Fatalf("not supported: desired=%q; supported=%q", desired, supported) - } - } - sort.SliceStable(matchLang, func(i, j int) bool { - return matchLang[i].distance < matchLang[j].distance - }) - b.w.WriteComment(` - matchLang holds pairs of langIDs of base languages that are typically - mutually intelligible. Each pair is associated with a confidence and - whether the intelligibility goes one or both ways.`) - b.w.WriteVar("matchLang", matchLang) - - b.w.WriteComment(` - matchScript holds pairs of scriptIDs where readers of one script - can typically also read the other. Each is associated with a confidence.`) - sort.SliceStable(matchScript, func(i, j int) bool { - return matchScript[i].distance < matchScript[j].distance - }) - b.w.WriteVar("matchScript", matchScript) - - sort.SliceStable(matchRegion, func(i, j int) bool { - return matchRegion[i].distance < matchRegion[j].distance - }) - b.w.WriteVar("matchRegion", matchRegion) -} diff --git a/vendor/golang.org/x/text/unicode/norm/maketables.go b/vendor/golang.org/x/text/unicode/norm/maketables.go deleted file mode 100644 index 30a3aa933..000000000 --- a/vendor/golang.org/x/text/unicode/norm/maketables.go +++ /dev/null @@ -1,986 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Normalization table generator. -// Data read from the web. -// See forminfo.go for a description of the trie values associated with each rune. - -package main - -import ( - "bytes" - "encoding/binary" - "flag" - "fmt" - "io" - "log" - "sort" - "strconv" - "strings" - - "golang.org/x/text/internal/gen" - "golang.org/x/text/internal/triegen" - "golang.org/x/text/internal/ucd" -) - -func main() { - gen.Init() - loadUnicodeData() - compactCCC() - loadCompositionExclusions() - completeCharFields(FCanonical) - completeCharFields(FCompatibility) - computeNonStarterCounts() - verifyComputed() - printChars() - testDerived() - printTestdata() - makeTables() -} - -var ( - tablelist = flag.String("tables", - "all", - "comma-separated list of which tables to generate; "+ - "can be 'decomp', 'recomp', 'info' and 'all'") - test = flag.Bool("test", - false, - "test existing tables against DerivedNormalizationProps and generate test data for regression testing") - verbose = flag.Bool("verbose", - false, - "write data to stdout as it is parsed") -) - -const MaxChar = 0x10FFFF // anything above this shouldn't exist - -// Quick Check properties of runes allow us to quickly -// determine whether a rune may occur in a normal form. -// For a given normal form, a rune may be guaranteed to occur -// verbatim (QC=Yes), may or may not combine with another -// rune (QC=Maybe), or may not occur (QC=No). -type QCResult int - -const ( - QCUnknown QCResult = iota - QCYes - QCNo - QCMaybe -) - -func (r QCResult) String() string { - switch r { - case QCYes: - return "Yes" - case QCNo: - return "No" - case QCMaybe: - return "Maybe" - } - return "***UNKNOWN***" -} - -const ( - FCanonical = iota // NFC or NFD - FCompatibility // NFKC or NFKD - FNumberOfFormTypes -) - -const ( - MComposed = iota // NFC or NFKC - MDecomposed // NFD or NFKD - MNumberOfModes -) - -// This contains only the properties we're interested in. -type Char struct { - name string - codePoint rune // if zero, this index is not a valid code point. - ccc uint8 // canonical combining class - origCCC uint8 - excludeInComp bool // from CompositionExclusions.txt - compatDecomp bool // it has a compatibility expansion - - nTrailingNonStarters uint8 - nLeadingNonStarters uint8 // must be equal to trailing if non-zero - - forms [FNumberOfFormTypes]FormInfo // For FCanonical and FCompatibility - - state State -} - -var chars = make([]Char, MaxChar+1) -var cccMap = make(map[uint8]uint8) - -func (c Char) String() string { - buf := new(bytes.Buffer) - - fmt.Fprintf(buf, "%U [%s]:\n", c.codePoint, c.name) - fmt.Fprintf(buf, " ccc: %v\n", c.ccc) - fmt.Fprintf(buf, " excludeInComp: %v\n", c.excludeInComp) - fmt.Fprintf(buf, " compatDecomp: %v\n", c.compatDecomp) - fmt.Fprintf(buf, " state: %v\n", c.state) - fmt.Fprintf(buf, " NFC:\n") - fmt.Fprint(buf, c.forms[FCanonical]) - fmt.Fprintf(buf, " NFKC:\n") - fmt.Fprint(buf, c.forms[FCompatibility]) - - return buf.String() -} - -// In UnicodeData.txt, some ranges are marked like this: -// 3400;;Lo;0;L;;;;;N;;;;; -// 4DB5;;Lo;0;L;;;;;N;;;;; -// parseCharacter keeps a state variable indicating the weirdness. -type State int - -const ( - SNormal State = iota // known to be zero for the type - SFirst - SLast - SMissing -) - -var lastChar = rune('\u0000') - -func (c Char) isValid() bool { - return c.codePoint != 0 && c.state != SMissing -} - -type FormInfo struct { - quickCheck [MNumberOfModes]QCResult // index: MComposed or MDecomposed - verified [MNumberOfModes]bool // index: MComposed or MDecomposed - - combinesForward bool // May combine with rune on the right - combinesBackward bool // May combine with rune on the left - isOneWay bool // Never appears in result - inDecomp bool // Some decompositions result in this char. - decomp Decomposition - expandedDecomp Decomposition -} - -func (f FormInfo) String() string { - buf := bytes.NewBuffer(make([]byte, 0)) - - fmt.Fprintf(buf, " quickCheck[C]: %v\n", f.quickCheck[MComposed]) - fmt.Fprintf(buf, " quickCheck[D]: %v\n", f.quickCheck[MDecomposed]) - fmt.Fprintf(buf, " cmbForward: %v\n", f.combinesForward) - fmt.Fprintf(buf, " cmbBackward: %v\n", f.combinesBackward) - fmt.Fprintf(buf, " isOneWay: %v\n", f.isOneWay) - fmt.Fprintf(buf, " inDecomp: %v\n", f.inDecomp) - fmt.Fprintf(buf, " decomposition: %X\n", f.decomp) - fmt.Fprintf(buf, " expandedDecomp: %X\n", f.expandedDecomp) - - return buf.String() -} - -type Decomposition []rune - -func parseDecomposition(s string, skipfirst bool) (a []rune, err error) { - decomp := strings.Split(s, " ") - if len(decomp) > 0 && skipfirst { - decomp = decomp[1:] - } - for _, d := range decomp { - point, err := strconv.ParseUint(d, 16, 64) - if err != nil { - return a, err - } - a = append(a, rune(point)) - } - return a, nil -} - -func loadUnicodeData() { - f := gen.OpenUCDFile("UnicodeData.txt") - defer f.Close() - p := ucd.New(f) - for p.Next() { - r := p.Rune(ucd.CodePoint) - char := &chars[r] - - char.ccc = uint8(p.Uint(ucd.CanonicalCombiningClass)) - decmap := p.String(ucd.DecompMapping) - - exp, err := parseDecomposition(decmap, false) - isCompat := false - if err != nil { - if len(decmap) > 0 { - exp, err = parseDecomposition(decmap, true) - if err != nil { - log.Fatalf(`%U: bad decomp |%v|: "%s"`, r, decmap, err) - } - isCompat = true - } - } - - char.name = p.String(ucd.Name) - char.codePoint = r - char.forms[FCompatibility].decomp = exp - if !isCompat { - char.forms[FCanonical].decomp = exp - } else { - char.compatDecomp = true - } - if len(decmap) > 0 { - char.forms[FCompatibility].decomp = exp - } - } - if err := p.Err(); err != nil { - log.Fatal(err) - } -} - -// compactCCC converts the sparse set of CCC values to a continguous one, -// reducing the number of bits needed from 8 to 6. -func compactCCC() { - m := make(map[uint8]uint8) - for i := range chars { - c := &chars[i] - m[c.ccc] = 0 - } - cccs := []int{} - for v, _ := range m { - cccs = append(cccs, int(v)) - } - sort.Ints(cccs) - for i, c := range cccs { - cccMap[uint8(i)] = uint8(c) - m[uint8(c)] = uint8(i) - } - for i := range chars { - c := &chars[i] - c.origCCC = c.ccc - c.ccc = m[c.ccc] - } - if len(m) >= 1<<6 { - log.Fatalf("too many difference CCC values: %d >= 64", len(m)) - } -} - -// CompositionExclusions.txt has form: -// 0958 # ... -// See https://unicode.org/reports/tr44/ for full explanation -func loadCompositionExclusions() { - f := gen.OpenUCDFile("CompositionExclusions.txt") - defer f.Close() - p := ucd.New(f) - for p.Next() { - c := &chars[p.Rune(0)] - if c.excludeInComp { - log.Fatalf("%U: Duplicate entry in exclusions.", c.codePoint) - } - c.excludeInComp = true - } - if e := p.Err(); e != nil { - log.Fatal(e) - } -} - -// hasCompatDecomp returns true if any of the recursive -// decompositions contains a compatibility expansion. -// In this case, the character may not occur in NFK*. -func hasCompatDecomp(r rune) bool { - c := &chars[r] - if c.compatDecomp { - return true - } - for _, d := range c.forms[FCompatibility].decomp { - if hasCompatDecomp(d) { - return true - } - } - return false -} - -// Hangul related constants. -const ( - HangulBase = 0xAC00 - HangulEnd = 0xD7A4 // hangulBase + Jamo combinations (19 * 21 * 28) - - JamoLBase = 0x1100 - JamoLEnd = 0x1113 - JamoVBase = 0x1161 - JamoVEnd = 0x1176 - JamoTBase = 0x11A8 - JamoTEnd = 0x11C3 - - JamoLVTCount = 19 * 21 * 28 - JamoTCount = 28 -) - -func isHangul(r rune) bool { - return HangulBase <= r && r < HangulEnd -} - -func isHangulWithoutJamoT(r rune) bool { - if !isHangul(r) { - return false - } - r -= HangulBase - return r < JamoLVTCount && r%JamoTCount == 0 -} - -func ccc(r rune) uint8 { - return chars[r].ccc -} - -// Insert a rune in a buffer, ordered by Canonical Combining Class. -func insertOrdered(b Decomposition, r rune) Decomposition { - n := len(b) - b = append(b, 0) - cc := ccc(r) - if cc > 0 { - // Use bubble sort. - for ; n > 0; n-- { - if ccc(b[n-1]) <= cc { - break - } - b[n] = b[n-1] - } - } - b[n] = r - return b -} - -// Recursively decompose. -func decomposeRecursive(form int, r rune, d Decomposition) Decomposition { - dcomp := chars[r].forms[form].decomp - if len(dcomp) == 0 { - return insertOrdered(d, r) - } - for _, c := range dcomp { - d = decomposeRecursive(form, c, d) - } - return d -} - -func completeCharFields(form int) { - // Phase 0: pre-expand decomposition. - for i := range chars { - f := &chars[i].forms[form] - if len(f.decomp) == 0 { - continue - } - exp := make(Decomposition, 0) - for _, c := range f.decomp { - exp = decomposeRecursive(form, c, exp) - } - f.expandedDecomp = exp - } - - // Phase 1: composition exclusion, mark decomposition. - for i := range chars { - c := &chars[i] - f := &c.forms[form] - - // Marks script-specific exclusions and version restricted. - f.isOneWay = c.excludeInComp - - // Singletons - f.isOneWay = f.isOneWay || len(f.decomp) == 1 - - // Non-starter decompositions - if len(f.decomp) > 1 { - chk := c.ccc != 0 || chars[f.decomp[0]].ccc != 0 - f.isOneWay = f.isOneWay || chk - } - - // Runes that decompose into more than two runes. - f.isOneWay = f.isOneWay || len(f.decomp) > 2 - - if form == FCompatibility { - f.isOneWay = f.isOneWay || hasCompatDecomp(c.codePoint) - } - - for _, r := range f.decomp { - chars[r].forms[form].inDecomp = true - } - } - - // Phase 2: forward and backward combining. - for i := range chars { - c := &chars[i] - f := &c.forms[form] - - if !f.isOneWay && len(f.decomp) == 2 { - f0 := &chars[f.decomp[0]].forms[form] - f1 := &chars[f.decomp[1]].forms[form] - if !f0.isOneWay { - f0.combinesForward = true - } - if !f1.isOneWay { - f1.combinesBackward = true - } - } - if isHangulWithoutJamoT(rune(i)) { - f.combinesForward = true - } - } - - // Phase 3: quick check values. - for i := range chars { - c := &chars[i] - f := &c.forms[form] - - switch { - case len(f.decomp) > 0: - f.quickCheck[MDecomposed] = QCNo - case isHangul(rune(i)): - f.quickCheck[MDecomposed] = QCNo - default: - f.quickCheck[MDecomposed] = QCYes - } - switch { - case f.isOneWay: - f.quickCheck[MComposed] = QCNo - case (i & 0xffff00) == JamoLBase: - f.quickCheck[MComposed] = QCYes - if JamoLBase <= i && i < JamoLEnd { - f.combinesForward = true - } - if JamoVBase <= i && i < JamoVEnd { - f.quickCheck[MComposed] = QCMaybe - f.combinesBackward = true - f.combinesForward = true - } - if JamoTBase <= i && i < JamoTEnd { - f.quickCheck[MComposed] = QCMaybe - f.combinesBackward = true - } - case !f.combinesBackward: - f.quickCheck[MComposed] = QCYes - default: - f.quickCheck[MComposed] = QCMaybe - } - } -} - -func computeNonStarterCounts() { - // Phase 4: leading and trailing non-starter count - for i := range chars { - c := &chars[i] - - runes := []rune{rune(i)} - // We always use FCompatibility so that the CGJ insertion points do not - // change for repeated normalizations with different forms. - if exp := c.forms[FCompatibility].expandedDecomp; len(exp) > 0 { - runes = exp - } - // We consider runes that combine backwards to be non-starters for the - // purpose of Stream-Safe Text Processing. - for _, r := range runes { - if cr := &chars[r]; cr.ccc == 0 && !cr.forms[FCompatibility].combinesBackward { - break - } - c.nLeadingNonStarters++ - } - for i := len(runes) - 1; i >= 0; i-- { - if cr := &chars[runes[i]]; cr.ccc == 0 && !cr.forms[FCompatibility].combinesBackward { - break - } - c.nTrailingNonStarters++ - } - if c.nTrailingNonStarters > 3 { - log.Fatalf("%U: Decomposition with more than 3 (%d) trailing modifiers (%U)", i, c.nTrailingNonStarters, runes) - } - - if isHangul(rune(i)) { - c.nTrailingNonStarters = 2 - if isHangulWithoutJamoT(rune(i)) { - c.nTrailingNonStarters = 1 - } - } - - if l, t := c.nLeadingNonStarters, c.nTrailingNonStarters; l > 0 && l != t { - log.Fatalf("%U: number of leading and trailing non-starters should be equal (%d vs %d)", i, l, t) - } - if t := c.nTrailingNonStarters; t > 3 { - log.Fatalf("%U: number of trailing non-starters is %d > 3", t) - } - } -} - -func printBytes(w io.Writer, b []byte, name string) { - fmt.Fprintf(w, "// %s: %d bytes\n", name, len(b)) - fmt.Fprintf(w, "var %s = [...]byte {", name) - for i, c := range b { - switch { - case i%64 == 0: - fmt.Fprintf(w, "\n// Bytes %x - %x\n", i, i+63) - case i%8 == 0: - fmt.Fprintf(w, "\n") - } - fmt.Fprintf(w, "0x%.2X, ", c) - } - fmt.Fprint(w, "\n}\n\n") -} - -// See forminfo.go for format. -func makeEntry(f *FormInfo, c *Char) uint16 { - e := uint16(0) - if r := c.codePoint; HangulBase <= r && r < HangulEnd { - e |= 0x40 - } - if f.combinesForward { - e |= 0x20 - } - if f.quickCheck[MDecomposed] == QCNo { - e |= 0x4 - } - switch f.quickCheck[MComposed] { - case QCYes: - case QCNo: - e |= 0x10 - case QCMaybe: - e |= 0x18 - default: - log.Fatalf("Illegal quickcheck value %v.", f.quickCheck[MComposed]) - } - e |= uint16(c.nTrailingNonStarters) - return e -} - -// decompSet keeps track of unique decompositions, grouped by whether -// the decomposition is followed by a trailing and/or leading CCC. -type decompSet [7]map[string]bool - -const ( - normalDecomp = iota - firstMulti - firstCCC - endMulti - firstLeadingCCC - firstCCCZeroExcept - firstStarterWithNLead - lastDecomp -) - -var cname = []string{"firstMulti", "firstCCC", "endMulti", "firstLeadingCCC", "firstCCCZeroExcept", "firstStarterWithNLead", "lastDecomp"} - -func makeDecompSet() decompSet { - m := decompSet{} - for i := range m { - m[i] = make(map[string]bool) - } - return m -} -func (m *decompSet) insert(key int, s string) { - m[key][s] = true -} - -func printCharInfoTables(w io.Writer) int { - mkstr := func(r rune, f *FormInfo) (int, string) { - d := f.expandedDecomp - s := string([]rune(d)) - if max := 1 << 6; len(s) >= max { - const msg = "%U: too many bytes in decomposition: %d >= %d" - log.Fatalf(msg, r, len(s), max) - } - head := uint8(len(s)) - if f.quickCheck[MComposed] != QCYes { - head |= 0x40 - } - if f.combinesForward { - head |= 0x80 - } - s = string([]byte{head}) + s - - lccc := ccc(d[0]) - tccc := ccc(d[len(d)-1]) - cc := ccc(r) - if cc != 0 && lccc == 0 && tccc == 0 { - log.Fatalf("%U: trailing and leading ccc are 0 for non-zero ccc %d", r, cc) - } - if tccc < lccc && lccc != 0 { - const msg = "%U: lccc (%d) must be <= tcc (%d)" - log.Fatalf(msg, r, lccc, tccc) - } - index := normalDecomp - nTrail := chars[r].nTrailingNonStarters - nLead := chars[r].nLeadingNonStarters - if tccc > 0 || lccc > 0 || nTrail > 0 { - tccc <<= 2 - tccc |= nTrail - s += string([]byte{tccc}) - index = endMulti - for _, r := range d[1:] { - if ccc(r) == 0 { - index = firstCCC - } - } - if lccc > 0 || nLead > 0 { - s += string([]byte{lccc}) - if index == firstCCC { - log.Fatalf("%U: multi-segment decomposition not supported for decompositions with leading CCC != 0", r) - } - index = firstLeadingCCC - } - if cc != lccc { - if cc != 0 { - log.Fatalf("%U: for lccc != ccc, expected ccc to be 0; was %d", r, cc) - } - index = firstCCCZeroExcept - } - } else if len(d) > 1 { - index = firstMulti - } - return index, s - } - - decompSet := makeDecompSet() - const nLeadStr = "\x00\x01" // 0-byte length and tccc with nTrail. - decompSet.insert(firstStarterWithNLead, nLeadStr) - - // Store the uniqued decompositions in a byte buffer, - // preceded by their byte length. - for _, c := range chars { - for _, f := range c.forms { - if len(f.expandedDecomp) == 0 { - continue - } - if f.combinesBackward { - log.Fatalf("%U: combinesBackward and decompose", c.codePoint) - } - index, s := mkstr(c.codePoint, &f) - decompSet.insert(index, s) - } - } - - decompositions := bytes.NewBuffer(make([]byte, 0, 10000)) - size := 0 - positionMap := make(map[string]uint16) - decompositions.WriteString("\000") - fmt.Fprintln(w, "const (") - for i, m := range decompSet { - sa := []string{} - for s := range m { - sa = append(sa, s) - } - sort.Strings(sa) - for _, s := range sa { - p := decompositions.Len() - decompositions.WriteString(s) - positionMap[s] = uint16(p) - } - if cname[i] != "" { - fmt.Fprintf(w, "%s = 0x%X\n", cname[i], decompositions.Len()) - } - } - fmt.Fprintln(w, "maxDecomp = 0x8000") - fmt.Fprintln(w, ")") - b := decompositions.Bytes() - printBytes(w, b, "decomps") - size += len(b) - - varnames := []string{"nfc", "nfkc"} - for i := 0; i < FNumberOfFormTypes; i++ { - trie := triegen.NewTrie(varnames[i]) - - for r, c := range chars { - f := c.forms[i] - d := f.expandedDecomp - if len(d) != 0 { - _, key := mkstr(c.codePoint, &f) - trie.Insert(rune(r), uint64(positionMap[key])) - if c.ccc != ccc(d[0]) { - // We assume the lead ccc of a decomposition !=0 in this case. - if ccc(d[0]) == 0 { - log.Fatalf("Expected leading CCC to be non-zero; ccc is %d", c.ccc) - } - } - } else if c.nLeadingNonStarters > 0 && len(f.expandedDecomp) == 0 && c.ccc == 0 && !f.combinesBackward { - // Handle cases where it can't be detected that the nLead should be equal - // to nTrail. - trie.Insert(c.codePoint, uint64(positionMap[nLeadStr])) - } else if v := makeEntry(&f, &c)<<8 | uint16(c.ccc); v != 0 { - trie.Insert(c.codePoint, uint64(0x8000|v)) - } - } - sz, err := trie.Gen(w, triegen.Compact(&normCompacter{name: varnames[i]})) - if err != nil { - log.Fatal(err) - } - size += sz - } - return size -} - -func contains(sa []string, s string) bool { - for _, a := range sa { - if a == s { - return true - } - } - return false -} - -func makeTables() { - w := &bytes.Buffer{} - - size := 0 - if *tablelist == "" { - return - } - list := strings.Split(*tablelist, ",") - if *tablelist == "all" { - list = []string{"recomp", "info"} - } - - // Compute maximum decomposition size. - max := 0 - for _, c := range chars { - if n := len(string(c.forms[FCompatibility].expandedDecomp)); n > max { - max = n - } - } - fmt.Fprintln(w, `import "sync"`) - fmt.Fprintln(w) - - fmt.Fprintln(w, "const (") - fmt.Fprintln(w, "\t// Version is the Unicode edition from which the tables are derived.") - fmt.Fprintf(w, "\tVersion = %q\n", gen.UnicodeVersion()) - fmt.Fprintln(w) - fmt.Fprintln(w, "\t// MaxTransformChunkSize indicates the maximum number of bytes that Transform") - fmt.Fprintln(w, "\t// may need to write atomically for any Form. Making a destination buffer at") - fmt.Fprintln(w, "\t// least this size ensures that Transform can always make progress and that") - fmt.Fprintln(w, "\t// the user does not need to grow the buffer on an ErrShortDst.") - fmt.Fprintf(w, "\tMaxTransformChunkSize = %d+maxNonStarters*4\n", len(string(0x034F))+max) - fmt.Fprintln(w, ")\n") - - // Print the CCC remap table. - size += len(cccMap) - fmt.Fprintf(w, "var ccc = [%d]uint8{", len(cccMap)) - for i := 0; i < len(cccMap); i++ { - if i%8 == 0 { - fmt.Fprintln(w) - } - fmt.Fprintf(w, "%3d, ", cccMap[uint8(i)]) - } - fmt.Fprintln(w, "\n}\n") - - if contains(list, "info") { - size += printCharInfoTables(w) - } - - if contains(list, "recomp") { - // Note that we use 32 bit keys, instead of 64 bit. - // This clips the bits of three entries, but we know - // this won't cause a collision. The compiler will catch - // any changes made to UnicodeData.txt that introduces - // a collision. - // Note that the recomposition map for NFC and NFKC - // are identical. - - // Recomposition map - nrentries := 0 - for _, c := range chars { - f := c.forms[FCanonical] - if !f.isOneWay && len(f.decomp) > 0 { - nrentries++ - } - } - sz := nrentries * 8 - size += sz - fmt.Fprintf(w, "// recompMap: %d bytes (entries only)\n", sz) - fmt.Fprintln(w, "var recompMap map[uint32]rune") - fmt.Fprintln(w, "var recompMapOnce sync.Once\n") - fmt.Fprintln(w, `const recompMapPacked = "" +`) - var buf [8]byte - for i, c := range chars { - f := c.forms[FCanonical] - d := f.decomp - if !f.isOneWay && len(d) > 0 { - key := uint32(uint16(d[0]))<<16 + uint32(uint16(d[1])) - binary.BigEndian.PutUint32(buf[:4], key) - binary.BigEndian.PutUint32(buf[4:], uint32(i)) - fmt.Fprintf(w, "\t\t%q + // 0x%.8X: 0x%.8X\n", string(buf[:]), key, uint32(i)) - } - } - // hack so we don't have to special case the trailing plus sign - fmt.Fprintf(w, ` ""`) - fmt.Fprintln(w) - } - - fmt.Fprintf(w, "// Total size of tables: %dKB (%d bytes)\n", (size+512)/1024, size) - gen.WriteVersionedGoFile("tables.go", "norm", w.Bytes()) -} - -func printChars() { - if *verbose { - for _, c := range chars { - if !c.isValid() || c.state == SMissing { - continue - } - fmt.Println(c) - } - } -} - -// verifyComputed does various consistency tests. -func verifyComputed() { - for i, c := range chars { - for _, f := range c.forms { - isNo := (f.quickCheck[MDecomposed] == QCNo) - if (len(f.decomp) > 0) != isNo && !isHangul(rune(i)) { - log.Fatalf("%U: NF*D QC must be No if rune decomposes", i) - } - - isMaybe := f.quickCheck[MComposed] == QCMaybe - if f.combinesBackward != isMaybe { - log.Fatalf("%U: NF*C QC must be Maybe if combinesBackward", i) - } - if len(f.decomp) > 0 && f.combinesForward && isMaybe { - log.Fatalf("%U: NF*C QC must be Yes or No if combinesForward and decomposes", i) - } - - if len(f.expandedDecomp) != 0 { - continue - } - if a, b := c.nLeadingNonStarters > 0, (c.ccc > 0 || f.combinesBackward); a != b { - // We accept these runes to be treated differently (it only affects - // segment breaking in iteration, most likely on improper use), but - // reconsider if more characters are added. - // U+FF9E HALFWIDTH KATAKANA VOICED SOUND MARK;Lm;0;L; 3099;;;;N;;;;; - // U+FF9F HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK;Lm;0;L; 309A;;;;N;;;;; - // U+3133 HANGUL LETTER KIYEOK-SIOS;Lo;0;L; 11AA;;;;N;HANGUL LETTER GIYEOG SIOS;;;; - // U+318E HANGUL LETTER ARAEAE;Lo;0;L; 11A1;;;;N;HANGUL LETTER ALAE AE;;;; - // U+FFA3 HALFWIDTH HANGUL LETTER KIYEOK-SIOS;Lo;0;L; 3133;;;;N;HALFWIDTH HANGUL LETTER GIYEOG SIOS;;;; - // U+FFDC HALFWIDTH HANGUL LETTER I;Lo;0;L; 3163;;;;N;;;;; - if i != 0xFF9E && i != 0xFF9F && !(0x3133 <= i && i <= 0x318E) && !(0xFFA3 <= i && i <= 0xFFDC) { - log.Fatalf("%U: nLead was %v; want %v", i, a, b) - } - } - } - nfc := c.forms[FCanonical] - nfkc := c.forms[FCompatibility] - if nfc.combinesBackward != nfkc.combinesBackward { - log.Fatalf("%U: Cannot combine combinesBackward\n", c.codePoint) - } - } -} - -// Use values in DerivedNormalizationProps.txt to compare against the -// values we computed. -// DerivedNormalizationProps.txt has form: -// 00C0..00C5 ; NFD_QC; N # ... -// 0374 ; NFD_QC; N # ... -// See https://unicode.org/reports/tr44/ for full explanation -func testDerived() { - f := gen.OpenUCDFile("DerivedNormalizationProps.txt") - defer f.Close() - p := ucd.New(f) - for p.Next() { - r := p.Rune(0) - c := &chars[r] - - var ftype, mode int - qt := p.String(1) - switch qt { - case "NFC_QC": - ftype, mode = FCanonical, MComposed - case "NFD_QC": - ftype, mode = FCanonical, MDecomposed - case "NFKC_QC": - ftype, mode = FCompatibility, MComposed - case "NFKD_QC": - ftype, mode = FCompatibility, MDecomposed - default: - continue - } - var qr QCResult - switch p.String(2) { - case "Y": - qr = QCYes - case "N": - qr = QCNo - case "M": - qr = QCMaybe - default: - log.Fatalf(`Unexpected quick check value "%s"`, p.String(2)) - } - if got := c.forms[ftype].quickCheck[mode]; got != qr { - log.Printf("%U: FAILED %s (was %v need %v)\n", r, qt, got, qr) - } - c.forms[ftype].verified[mode] = true - } - if err := p.Err(); err != nil { - log.Fatal(err) - } - // Any unspecified value must be QCYes. Verify this. - for i, c := range chars { - for j, fd := range c.forms { - for k, qr := range fd.quickCheck { - if !fd.verified[k] && qr != QCYes { - m := "%U: FAIL F:%d M:%d (was %v need Yes) %s\n" - log.Printf(m, i, j, k, qr, c.name) - } - } - } - } -} - -var testHeader = `const ( - Yes = iota - No - Maybe -) - -type formData struct { - qc uint8 - combinesForward bool - decomposition string -} - -type runeData struct { - r rune - ccc uint8 - nLead uint8 - nTrail uint8 - f [2]formData // 0: canonical; 1: compatibility -} - -func f(qc uint8, cf bool, dec string) [2]formData { - return [2]formData{{qc, cf, dec}, {qc, cf, dec}} -} - -func g(qc, qck uint8, cf, cfk bool, d, dk string) [2]formData { - return [2]formData{{qc, cf, d}, {qck, cfk, dk}} -} - -var testData = []runeData{ -` - -func printTestdata() { - type lastInfo struct { - ccc uint8 - nLead uint8 - nTrail uint8 - f string - } - - last := lastInfo{} - w := &bytes.Buffer{} - fmt.Fprintf(w, testHeader) - for r, c := range chars { - f := c.forms[FCanonical] - qc, cf, d := f.quickCheck[MComposed], f.combinesForward, string(f.expandedDecomp) - f = c.forms[FCompatibility] - qck, cfk, dk := f.quickCheck[MComposed], f.combinesForward, string(f.expandedDecomp) - s := "" - if d == dk && qc == qck && cf == cfk { - s = fmt.Sprintf("f(%s, %v, %q)", qc, cf, d) - } else { - s = fmt.Sprintf("g(%s, %s, %v, %v, %q, %q)", qc, qck, cf, cfk, d, dk) - } - current := lastInfo{c.ccc, c.nLeadingNonStarters, c.nTrailingNonStarters, s} - if last != current { - fmt.Fprintf(w, "\t{0x%x, %d, %d, %d, %s},\n", r, c.origCCC, c.nLeadingNonStarters, c.nTrailingNonStarters, s) - last = current - } - } - fmt.Fprintln(w, "}") - gen.WriteVersionedGoFile("data_test.go", "norm", w.Bytes()) -} diff --git a/vendor/golang.org/x/text/unicode/norm/triegen.go b/vendor/golang.org/x/text/unicode/norm/triegen.go deleted file mode 100644 index 45d711900..000000000 --- a/vendor/golang.org/x/text/unicode/norm/triegen.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Trie table generator. -// Used by make*tables tools to generate a go file with trie data structures -// for mapping UTF-8 to a 16-bit value. All but the last byte in a UTF-8 byte -// sequence are used to lookup offsets in the index table to be used for the -// next byte. The last byte is used to index into a table with 16-bit values. - -package main - -import ( - "fmt" - "io" -) - -const maxSparseEntries = 16 - -type normCompacter struct { - sparseBlocks [][]uint64 - sparseOffset []uint16 - sparseCount int - name string -} - -func mostFrequentStride(a []uint64) int { - counts := make(map[int]int) - var v int - for _, x := range a { - if stride := int(x) - v; v != 0 && stride >= 0 { - counts[stride]++ - } - v = int(x) - } - var maxs, maxc int - for stride, cnt := range counts { - if cnt > maxc || (cnt == maxc && stride < maxs) { - maxs, maxc = stride, cnt - } - } - return maxs -} - -func countSparseEntries(a []uint64) int { - stride := mostFrequentStride(a) - var v, count int - for _, tv := range a { - if int(tv)-v != stride { - if tv != 0 { - count++ - } - } - v = int(tv) - } - return count -} - -func (c *normCompacter) Size(v []uint64) (sz int, ok bool) { - if n := countSparseEntries(v); n <= maxSparseEntries { - return (n+1)*4 + 2, true - } - return 0, false -} - -func (c *normCompacter) Store(v []uint64) uint32 { - h := uint32(len(c.sparseOffset)) - c.sparseBlocks = append(c.sparseBlocks, v) - c.sparseOffset = append(c.sparseOffset, uint16(c.sparseCount)) - c.sparseCount += countSparseEntries(v) + 1 - return h -} - -func (c *normCompacter) Handler() string { - return c.name + "Sparse.lookup" -} - -func (c *normCompacter) Print(w io.Writer) (retErr error) { - p := func(f string, x ...interface{}) { - if _, err := fmt.Fprintf(w, f, x...); retErr == nil && err != nil { - retErr = err - } - } - - ls := len(c.sparseBlocks) - p("// %sSparseOffset: %d entries, %d bytes\n", c.name, ls, ls*2) - p("var %sSparseOffset = %#v\n\n", c.name, c.sparseOffset) - - ns := c.sparseCount - p("// %sSparseValues: %d entries, %d bytes\n", c.name, ns, ns*4) - p("var %sSparseValues = [%d]valueRange {", c.name, ns) - for i, b := range c.sparseBlocks { - p("\n// Block %#x, offset %#x", i, c.sparseOffset[i]) - var v int - stride := mostFrequentStride(b) - n := countSparseEntries(b) - p("\n{value:%#04x,lo:%#02x},", stride, uint8(n)) - for i, nv := range b { - if int(nv)-v != stride { - if v != 0 { - p(",hi:%#02x},", 0x80+i-1) - } - if nv != 0 { - p("\n{value:%#04x,lo:%#02x", nv, 0x80+i) - } - } - v = int(nv) - } - if v != 0 { - p(",hi:%#02x},", 0x80+len(b)-1) - } - } - p("\n}\n\n") - return -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 417988fd8..4ea959767 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2,7 +2,7 @@ github.com/NaySoftware/go-fcm # github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 github.com/StackExchange/wmi -# github.com/allegro/bigcache v0.0.0-20190218064605-e24eb225f156 +# github.com/allegro/bigcache v1.1.0 github.com/allegro/bigcache github.com/allegro/bigcache/queue # github.com/aristanetworks/goarista v0.0.0-20190704150520-f44d68189fd7 @@ -30,83 +30,83 @@ github.com/edsrzf/mmap-go github.com/elastic/gosigar github.com/elastic/gosigar/sys/windows # github.com/ethereum/go-ethereum v1.9.5 => github.com/status-im/go-ethereum v1.9.5-status.4 -github.com/ethereum/go-ethereum/accounts -github.com/ethereum/go-ethereum/accounts/keystore -github.com/ethereum/go-ethereum/common -github.com/ethereum/go-ethereum/common/hexutil -github.com/ethereum/go-ethereum/crypto -github.com/ethereum/go-ethereum/ethclient -github.com/ethereum/go-ethereum/event -github.com/ethereum/go-ethereum/log -github.com/ethereum/go-ethereum/node -github.com/ethereum/go-ethereum/p2p/enode -github.com/ethereum/go-ethereum/p2p/discv5 -github.com/ethereum/go-ethereum/p2p -github.com/ethereum/go-ethereum/metrics github.com/ethereum/go-ethereum -github.com/ethereum/go-ethereum/accounts/abi/bind -github.com/ethereum/go-ethereum/core/types +github.com/ethereum/go-ethereum/accounts github.com/ethereum/go-ethereum/accounts/abi -github.com/ethereum/go-ethereum/crypto/ecies -github.com/ethereum/go-ethereum/p2p/enr -github.com/ethereum/go-ethereum/rlp -github.com/ethereum/go-ethereum/core -github.com/ethereum/go-ethereum/eth -github.com/ethereum/go-ethereum/eth/downloader -github.com/ethereum/go-ethereum/les -github.com/ethereum/go-ethereum/p2p/nat -github.com/ethereum/go-ethereum/params -github.com/ethereum/go-ethereum/common/mclock -github.com/ethereum/go-ethereum/rpc -github.com/ethereum/go-ethereum/ethapi -github.com/ethereum/go-ethereum/eth/filters -github.com/ethereum/go-ethereum/consensus/ethash -github.com/ethereum/go-ethereum/common/math -github.com/ethereum/go-ethereum/crypto/secp256k1 +github.com/ethereum/go-ethereum/accounts/abi/bind +github.com/ethereum/go-ethereum/accounts/abi/bind/backends github.com/ethereum/go-ethereum/accounts/external +github.com/ethereum/go-ethereum/accounts/keystore github.com/ethereum/go-ethereum/accounts/scwallet github.com/ethereum/go-ethereum/accounts/usbwallet -github.com/ethereum/go-ethereum/core/rawdb -github.com/ethereum/go-ethereum/ethdb -github.com/ethereum/go-ethereum/internal/debug -github.com/ethereum/go-ethereum/p2p/netutil +github.com/ethereum/go-ethereum/accounts/usbwallet/trezor +github.com/ethereum/go-ethereum/common github.com/ethereum/go-ethereum/common/bitutil -github.com/ethereum/go-ethereum/p2p/discover -github.com/ethereum/go-ethereum/trie -github.com/ethereum/go-ethereum/accounts/abi/bind/backends +github.com/ethereum/go-ethereum/common/fdlimit +github.com/ethereum/go-ethereum/common/hexutil +github.com/ethereum/go-ethereum/common/math +github.com/ethereum/go-ethereum/common/mclock github.com/ethereum/go-ethereum/common/prque github.com/ethereum/go-ethereum/consensus -github.com/ethereum/go-ethereum/consensus/misc -github.com/ethereum/go-ethereum/core/state -github.com/ethereum/go-ethereum/core/vm github.com/ethereum/go-ethereum/consensus/clique -github.com/ethereum/go-ethereum/core/bloombits -github.com/ethereum/go-ethereum/core/forkid -github.com/ethereum/go-ethereum/eth/fetcher -github.com/ethereum/go-ethereum/eth/gasprice -github.com/ethereum/go-ethereum/eth/tracers -github.com/ethereum/go-ethereum/internal/ethapi -github.com/ethereum/go-ethereum/miner +github.com/ethereum/go-ethereum/consensus/ethash +github.com/ethereum/go-ethereum/consensus/misc github.com/ethereum/go-ethereum/contracts/checkpointoracle github.com/ethereum/go-ethereum/contracts/checkpointoracle/contract -github.com/ethereum/go-ethereum/les/flowcontrol -github.com/ethereum/go-ethereum/light -github.com/ethereum/go-ethereum/signer/core -github.com/ethereum/go-ethereum/accounts/usbwallet/trezor -github.com/ethereum/go-ethereum/ethdb/leveldb -github.com/ethereum/go-ethereum/ethdb/memorydb -github.com/ethereum/go-ethereum/metrics/exp +github.com/ethereum/go-ethereum/core +github.com/ethereum/go-ethereum/core/bloombits +github.com/ethereum/go-ethereum/core/forkid +github.com/ethereum/go-ethereum/core/rawdb +github.com/ethereum/go-ethereum/core/state +github.com/ethereum/go-ethereum/core/types +github.com/ethereum/go-ethereum/core/vm +github.com/ethereum/go-ethereum/crypto github.com/ethereum/go-ethereum/crypto/blake2b github.com/ethereum/go-ethereum/crypto/bn256 -github.com/ethereum/go-ethereum/eth/tracers/internal/tracers -github.com/ethereum/go-ethereum/common/fdlimit -github.com/ethereum/go-ethereum/signer/storage -github.com/ethereum/go-ethereum/metrics/prometheus github.com/ethereum/go-ethereum/crypto/bn256/cloudflare github.com/ethereum/go-ethereum/crypto/bn256/google +github.com/ethereum/go-ethereum/crypto/ecies +github.com/ethereum/go-ethereum/crypto/secp256k1 +github.com/ethereum/go-ethereum/eth +github.com/ethereum/go-ethereum/eth/downloader +github.com/ethereum/go-ethereum/eth/fetcher +github.com/ethereum/go-ethereum/eth/filters +github.com/ethereum/go-ethereum/eth/gasprice +github.com/ethereum/go-ethereum/eth/tracers +github.com/ethereum/go-ethereum/eth/tracers/internal/tracers +github.com/ethereum/go-ethereum/ethapi +github.com/ethereum/go-ethereum/ethclient +github.com/ethereum/go-ethereum/ethdb +github.com/ethereum/go-ethereum/ethdb/leveldb +github.com/ethereum/go-ethereum/ethdb/memorydb +github.com/ethereum/go-ethereum/event +github.com/ethereum/go-ethereum/internal/debug +github.com/ethereum/go-ethereum/internal/ethapi +github.com/ethereum/go-ethereum/les +github.com/ethereum/go-ethereum/les/flowcontrol +github.com/ethereum/go-ethereum/light +github.com/ethereum/go-ethereum/log +github.com/ethereum/go-ethereum/metrics +github.com/ethereum/go-ethereum/metrics/exp +github.com/ethereum/go-ethereum/metrics/prometheus +github.com/ethereum/go-ethereum/miner +github.com/ethereum/go-ethereum/node +github.com/ethereum/go-ethereum/p2p +github.com/ethereum/go-ethereum/p2p/discover +github.com/ethereum/go-ethereum/p2p/discv5 +github.com/ethereum/go-ethereum/p2p/enode +github.com/ethereum/go-ethereum/p2p/enr +github.com/ethereum/go-ethereum/p2p/nat +github.com/ethereum/go-ethereum/p2p/netutil +github.com/ethereum/go-ethereum/params +github.com/ethereum/go-ethereum/rlp +github.com/ethereum/go-ethereum/rpc +github.com/ethereum/go-ethereum/signer/core +github.com/ethereum/go-ethereum/signer/storage +github.com/ethereum/go-ethereum/trie # github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc -github.com/fjl/memsize/memsizeui github.com/fjl/memsize +github.com/fjl/memsize/memsizeui # github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff github.com/gballet/go-libpcsclite # github.com/go-ole/go-ole v1.2.1 @@ -120,12 +120,12 @@ github.com/go-playground/universal-translator # github.com/go-stack/stack v1.8.0 github.com/go-stack/stack # github.com/gogo/protobuf v1.3.0 -github.com/gogo/protobuf/proto github.com/gogo/protobuf/io +github.com/gogo/protobuf/proto # github.com/golang-migrate/migrate/v4 v4.5.0 -github.com/golang-migrate/migrate/v4/source -github.com/golang-migrate/migrate/v4/database github.com/golang-migrate/migrate/v4 +github.com/golang-migrate/migrate/v4/database +github.com/golang-migrate/migrate/v4/source # github.com/golang/mock v1.3.1 github.com/golang/mock/gomock # github.com/golang/protobuf v1.3.2 @@ -159,8 +159,8 @@ github.com/ipfs/go-ipfs-util # github.com/ipfs/go-log v0.0.1 github.com/ipfs/go-log github.com/ipfs/go-log/tracer -github.com/ipfs/go-log/writer github.com/ipfs/go-log/tracer/wire +github.com/ipfs/go-log/writer # github.com/jackpal/gateway v1.0.5 github.com/jackpal/gateway # github.com/jackpal/go-nat-pmp v1.0.1 @@ -201,8 +201,8 @@ github.com/libp2p/go-libp2p/p2p/host/basic github.com/libp2p/go-libp2p/p2p/host/relay github.com/libp2p/go-libp2p/p2p/host/routed github.com/libp2p/go-libp2p/p2p/protocol/identify -github.com/libp2p/go-libp2p/p2p/protocol/ping github.com/libp2p/go-libp2p/p2p/protocol/identify/pb +github.com/libp2p/go-libp2p/p2p/protocol/ping # github.com/libp2p/go-libp2p-autonat v0.1.0 github.com/libp2p/go-libp2p-autonat github.com/libp2p/go-libp2p-autonat/pb @@ -210,25 +210,25 @@ github.com/libp2p/go-libp2p-autonat/pb github.com/libp2p/go-libp2p-circuit github.com/libp2p/go-libp2p-circuit/pb # github.com/libp2p/go-libp2p-core v0.2.3 +github.com/libp2p/go-libp2p-core/connmgr github.com/libp2p/go-libp2p-core/crypto +github.com/libp2p/go-libp2p-core/crypto/pb +github.com/libp2p/go-libp2p-core/discovery +github.com/libp2p/go-libp2p-core/event github.com/libp2p/go-libp2p-core/helpers github.com/libp2p/go-libp2p-core/host +github.com/libp2p/go-libp2p-core/metrics +github.com/libp2p/go-libp2p-core/mux github.com/libp2p/go-libp2p-core/network github.com/libp2p/go-libp2p-core/peer -github.com/libp2p/go-libp2p-core/protocol -github.com/libp2p/go-libp2p-core/connmgr -github.com/libp2p/go-libp2p-core/metrics github.com/libp2p/go-libp2p-core/peerstore github.com/libp2p/go-libp2p-core/pnet -github.com/libp2p/go-libp2p-core/crypto/pb -github.com/libp2p/go-libp2p-core/event -github.com/libp2p/go-libp2p-core/mux -github.com/libp2p/go-libp2p-core/transport -github.com/libp2p/go-libp2p-core/sec +github.com/libp2p/go-libp2p-core/protocol github.com/libp2p/go-libp2p-core/routing +github.com/libp2p/go-libp2p-core/sec github.com/libp2p/go-libp2p-core/sec/insecure github.com/libp2p/go-libp2p-core/sec/insecure/pb -github.com/libp2p/go-libp2p-core/discovery +github.com/libp2p/go-libp2p-core/transport # github.com/libp2p/go-libp2p-discovery v0.1.0 github.com/libp2p/go-libp2p-discovery # github.com/libp2p/go-libp2p-loggables v0.1.0 @@ -238,9 +238,9 @@ github.com/libp2p/go-libp2p-mplex # github.com/libp2p/go-libp2p-nat v0.0.4 github.com/libp2p/go-libp2p-nat # github.com/libp2p/go-libp2p-peerstore v0.1.3 -github.com/libp2p/go-libp2p-peerstore/pstoremem github.com/libp2p/go-libp2p-peerstore github.com/libp2p/go-libp2p-peerstore/addr +github.com/libp2p/go-libp2p-peerstore/pstoremem # github.com/libp2p/go-libp2p-secio v0.2.0 github.com/libp2p/go-libp2p-secio github.com/libp2p/go-libp2p-secio/pb @@ -338,71 +338,74 @@ github.com/status-im/go-multiaddr-ethv4 # github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 github.com/status-im/keycard-go/derivationpath # github.com/status-im/migrate/v4 v4.3.1-status.0.20190822050738-a9d340ec8fb7 -github.com/status-im/migrate/v4/source/go_bindata github.com/status-im/migrate/v4 github.com/status-im/migrate/v4/database/postgres github.com/status-im/migrate/v4/database/sqlcipher +github.com/status-im/migrate/v4/source/go_bindata # github.com/status-im/rendezvous v1.3.0 github.com/status-im/rendezvous github.com/status-im/rendezvous/protocol github.com/status-im/rendezvous/server -# github.com/status-im/status-protocol-go v0.2.3-0.20190926081215-cc44ddb7ce44 +# github.com/status-im/status-protocol-go v0.2.3-0.20191009073015-e7ecec99a52b github.com/status-im/status-protocol-go -github.com/status-im/status-protocol-go/zaputil -github.com/status-im/status-protocol-go/encryption/multidevice -github.com/status-im/status-protocol-go/transport/whisper +github.com/status-im/status-protocol-go/applicationmetadata +github.com/status-im/status-protocol-go/crypto github.com/status-im/status-protocol-go/datasync github.com/status-im/status-protocol-go/datasync/peer github.com/status-im/status-protocol-go/encryption github.com/status-im/status-protocol-go/encryption/migrations +github.com/status-im/status-protocol-go/encryption/multidevice +github.com/status-im/status-protocol-go/encryption/publisher github.com/status-im/status-protocol-go/encryption/sharedsecret github.com/status-im/status-protocol-go/identity/alias github.com/status-im/status-protocol-go/identity/identicon github.com/status-im/status-protocol-go/migrations github.com/status-im/status-protocol-go/sqlite +github.com/status-im/status-protocol-go/transport/whisper +github.com/status-im/status-protocol-go/transport/whisper/gethbridge github.com/status-im/status-protocol-go/transport/whisper/migrations +github.com/status-im/status-protocol-go/transport/whisper/types +github.com/status-im/status-protocol-go/types github.com/status-im/status-protocol-go/v1 -github.com/status-im/status-protocol-go/crypto -github.com/status-im/status-protocol-go/encryption/publisher -github.com/status-im/status-protocol-go/applicationmetadata -# github.com/status-im/whisper v1.4.14 +github.com/status-im/status-protocol-go/zaputil +# github.com/status-im/whisper v1.5.1 github.com/status-im/whisper/whisperv6 # github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 github.com/steakknife/bloomfilter # github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 github.com/steakknife/hamming # github.com/stretchr/testify v1.4.0 +github.com/stretchr/testify/assert github.com/stretchr/testify/require github.com/stretchr/testify/suite -github.com/stretchr/testify/assert # github.com/syndtr/goleveldb v1.0.0 github.com/syndtr/goleveldb/leveldb -github.com/syndtr/goleveldb/leveldb/errors -github.com/syndtr/goleveldb/leveldb/iterator -github.com/syndtr/goleveldb/leveldb/opt -github.com/syndtr/goleveldb/leveldb/storage -github.com/syndtr/goleveldb/leveldb/util github.com/syndtr/goleveldb/leveldb/cache github.com/syndtr/goleveldb/leveldb/comparer +github.com/syndtr/goleveldb/leveldb/errors github.com/syndtr/goleveldb/leveldb/filter +github.com/syndtr/goleveldb/leveldb/iterator github.com/syndtr/goleveldb/leveldb/journal github.com/syndtr/goleveldb/leveldb/memdb +github.com/syndtr/goleveldb/leveldb/opt +github.com/syndtr/goleveldb/leveldb/storage github.com/syndtr/goleveldb/leveldb/table +github.com/syndtr/goleveldb/leveldb/util # github.com/tyler-smith/go-bip39 v1.0.2 github.com/tyler-smith/go-bip39 github.com/tyler-smith/go-bip39/wordlists # github.com/vacp2p/mvds v0.0.21 github.com/vacp2p/mvds/node +github.com/vacp2p/mvds/node/migrations +github.com/vacp2p/mvds/peers +github.com/vacp2p/mvds/peers/migrations +github.com/vacp2p/mvds/persistenceutil github.com/vacp2p/mvds/protobuf github.com/vacp2p/mvds/state -github.com/vacp2p/mvds/transport -github.com/vacp2p/mvds/persistenceutil -github.com/vacp2p/mvds/peers -github.com/vacp2p/mvds/store -github.com/vacp2p/mvds/node/migrations -github.com/vacp2p/mvds/peers/migrations github.com/vacp2p/mvds/state/migrations +github.com/vacp2p/mvds/store github.com/vacp2p/mvds/store/migrations +github.com/vacp2p/mvds/transport # github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc github.com/whyrusleeping/go-logging # github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f @@ -414,45 +417,45 @@ github.com/whyrusleeping/multiaddr-filter # github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 github.com/wsddn/go-ecdh # go.opencensus.io v0.22.1 -go.opencensus.io/stats/view go.opencensus.io/internal/tagencoding go.opencensus.io/metric/metricdata go.opencensus.io/metric/metricproducer +go.opencensus.io/resource go.opencensus.io/stats go.opencensus.io/stats/internal +go.opencensus.io/stats/view go.opencensus.io/tag -go.opencensus.io/resource # go.uber.org/atomic v1.4.0 go.uber.org/atomic # go.uber.org/multierr v1.1.0 go.uber.org/multierr # go.uber.org/zap v1.10.0 go.uber.org/zap -go.uber.org/zap/zapcore -go.uber.org/zap/internal/bufferpool go.uber.org/zap/buffer +go.uber.org/zap/internal/bufferpool go.uber.org/zap/internal/color go.uber.org/zap/internal/exit +go.uber.org/zap/zapcore # golang.org/x/crypto v0.0.0-20191001141032-4663e185863a -golang.org/x/crypto/sha3 -golang.org/x/crypto/ssh/terminal -golang.org/x/crypto/hkdf -golang.org/x/crypto/pbkdf2 -golang.org/x/crypto/scrypt -golang.org/x/crypto/curve25519 -golang.org/x/crypto/ripemd160 golang.org/x/crypto/blake2s +golang.org/x/crypto/curve25519 golang.org/x/crypto/ed25519 golang.org/x/crypto/ed25519/internal/edwards25519 +golang.org/x/crypto/hkdf +golang.org/x/crypto/pbkdf2 +golang.org/x/crypto/ripemd160 +golang.org/x/crypto/scrypt +golang.org/x/crypto/sha3 +golang.org/x/crypto/ssh/terminal # golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 -golang.org/x/net/context -golang.org/x/net/ipv4 -golang.org/x/net/html/charset golang.org/x/net/bpf -golang.org/x/net/internal/iana -golang.org/x/net/internal/socket +golang.org/x/net/context golang.org/x/net/html golang.org/x/net/html/atom +golang.org/x/net/html/charset +golang.org/x/net/internal/iana +golang.org/x/net/internal/socket +golang.org/x/net/ipv4 # golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e golang.org/x/sync/syncmap # golang.org/x/sys v0.0.0-20190927073244-c990c680b611 @@ -460,24 +463,24 @@ golang.org/x/sys/cpu golang.org/x/sys/unix golang.org/x/sys/windows # golang.org/x/text v0.3.2 -golang.org/x/text/unicode/norm -golang.org/x/text/transform golang.org/x/text/encoding golang.org/x/text/encoding/charmap golang.org/x/text/encoding/htmlindex -golang.org/x/text/encoding/internal/identifier golang.org/x/text/encoding/internal +golang.org/x/text/encoding/internal/identifier golang.org/x/text/encoding/japanese golang.org/x/text/encoding/korean golang.org/x/text/encoding/simplifiedchinese golang.org/x/text/encoding/traditionalchinese golang.org/x/text/encoding/unicode -golang.org/x/text/language -golang.org/x/text/internal/utf8internal -golang.org/x/text/runes golang.org/x/text/internal/language golang.org/x/text/internal/language/compact golang.org/x/text/internal/tag +golang.org/x/text/internal/utf8internal +golang.org/x/text/language +golang.org/x/text/runes +golang.org/x/text/transform +golang.org/x/text/unicode/norm # gopkg.in/go-playground/validator.v9 v9.29.1 gopkg.in/go-playground/validator.v9 # gopkg.in/natefinch/lumberjack.v2 v2.0.0