mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
swarm, pot: fix unnecessary conversions as reported by travis
This commit is contained in:
parent
136b93775b
commit
e0086dd33a
11 changed files with 18 additions and 18 deletions
|
|
@ -111,7 +111,7 @@ func posProximity(one, other Address, pos int) (ret int, eq bool) {
|
|||
start = pos % 8
|
||||
}
|
||||
for j := start; j < 8; j++ {
|
||||
if (uint8(oxo)>>uint8(7-j))&0x01 != 0 {
|
||||
if (oxo>>uint8(7-j))&0x01 != 0 {
|
||||
return i*8 + j, false
|
||||
}
|
||||
}
|
||||
|
|
@ -173,13 +173,13 @@ func RandomAddress() Address {
|
|||
func NewAddressFromString(s string) []byte {
|
||||
ha := [32]byte{}
|
||||
|
||||
t := s + string(zerosBin)[:len(zerosBin)-len(s)]
|
||||
t := s + zerosBin[:len(zerosBin)-len(s)]
|
||||
for i := 0; i < 4; i++ {
|
||||
n, err := strconv.ParseUint(t[i*64:(i+1)*64], 2, 64)
|
||||
if err != nil {
|
||||
panic("wrong format: " + err.Error())
|
||||
}
|
||||
binary.BigEndian.PutUint64(ha[i*8:(i+1)*8], uint64(n))
|
||||
binary.BigEndian.PutUint64(ha[i*8:(i+1)*8], n)
|
||||
}
|
||||
return ha[:]
|
||||
}
|
||||
|
|
@ -229,7 +229,7 @@ func proximityOrder(one, other []byte, pos int) (int, bool) {
|
|||
start = pos % 8
|
||||
}
|
||||
for j := start; j < 8; j++ {
|
||||
if (uint8(oxo)>>uint8(7-j))&0x01 != 0 {
|
||||
if (oxo>>uint8(7-j))&0x01 != 0 {
|
||||
return i*8 + j, false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func NewFromBytes(b []byte, l int) (bv *BitVector, err error) {
|
|||
|
||||
func (bv *BitVector) Get(i int) bool {
|
||||
bi := i / 8
|
||||
return uint8(bv.b[bi])&(0x1<<uint(i%8)) != 0
|
||||
return bv.b[bi]&(0x1<<uint(i%8)) != 0
|
||||
}
|
||||
|
||||
func (bv *BitVector) Set(i int, v bool) {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func (r *RemoteSectionReader) Read(b []byte) (n int64, err error) {
|
|||
end = true
|
||||
}
|
||||
copy(b[n:], chunk.SData[:m])
|
||||
n += int64(m)
|
||||
n += m
|
||||
}
|
||||
|
||||
for {
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ R:
|
|||
// this should be has locally
|
||||
chunk, err := d.db.Get(req.Key)
|
||||
if !bytes.Equal(chunk.Key, req.Key) {
|
||||
panic(fmt.Errorf("processReceivedChunks: chunk key %s != req key %s (peer %s)", chunk.Key.Hex(), storage.Key(req.Key).Hex(), req.peer.ID()))
|
||||
panic(fmt.Errorf("processReceivedChunks: chunk key %s != req key %s (peer %s)", chunk.Key.Hex(), req.Key.Hex(), req.peer.ID()))
|
||||
}
|
||||
if err == nil {
|
||||
continue R
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ func keyToString(key []byte) string {
|
|||
if l == 0 {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s-%d", string(key[:l-1]), uint8(key[l-1]))
|
||||
return fmt.Sprintf("%s-%d", string(key[:l-1]), key[l-1])
|
||||
}
|
||||
|
||||
type server struct {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ const maxPO = 32
|
|||
|
||||
func RegisterSwarmSyncerServer(streamer *Registry, db *storage.DBAPI) {
|
||||
streamer.RegisterServerFunc("SYNC", func(p *Peer, t []byte) (Server, error) {
|
||||
po := uint8(t[0])
|
||||
po := t[0]
|
||||
// TODO: make this work for HISTORY too
|
||||
return NewSwarmSyncerServer(false, po, db)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ func (pssapi *API) BaseAddr() (PssAddress, error) {
|
|||
func (pssapi *API) GetPublicKey() (keybytes hexutil.Bytes) {
|
||||
key := pssapi.Pss.PublicKey()
|
||||
keybytes = crypto.FromECDSAPub(key)
|
||||
return hexutil.Bytes(keybytes)
|
||||
return keybytes
|
||||
}
|
||||
|
||||
// Set Public key to associate with a particular Pss peer
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ func (self *HandshakeAPI) Handshake(pubkeyid string, topic Topic, sync bool, flu
|
|||
keycount = self.ctrl.symKeyCapacity
|
||||
} else {
|
||||
validkeys := self.ctrl.validKeys(pubkeyid, &topic, false)
|
||||
keycount = uint8(self.ctrl.symKeyCapacity - uint8(len(validkeys)))
|
||||
keycount = self.ctrl.symKeyCapacity - uint8(len(validkeys))
|
||||
}
|
||||
if keycount == 0 {
|
||||
return keys, errors.New("Incoming symmetric key store is already full")
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ func (self *LazyChunkReader) ReadAt(b []byte, off int64) (read int, err error) {
|
|||
return 0, err
|
||||
}
|
||||
if off+int64(len(b)) >= size {
|
||||
return int(size - int64(off)), io.EOF
|
||||
return int(size - off), io.EOF
|
||||
}
|
||||
return len(b), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func NewDbStore(path string, hash SwarmHasher, capacity uint64, po func(Key) uin
|
|||
for i := 0; i < 0x100; i++ {
|
||||
k := make([]byte, 2)
|
||||
k[0] = keyDistanceCnt
|
||||
k[1] = byte(uint8(i))
|
||||
k[1] = uint8(i)
|
||||
cnt, _ := s.db.Get(k)
|
||||
s.bucketCnt[i] = BytesToU64(cnt)
|
||||
s.bucketCnt[i]++
|
||||
|
|
@ -211,7 +211,7 @@ func getOldDataKey(idx uint64) []byte {
|
|||
func getDataKey(idx uint64, po uint8) []byte {
|
||||
key := make([]byte, 10)
|
||||
key[0] = keyData
|
||||
key[1] = byte(po)
|
||||
key[1] = po
|
||||
binary.BigEndian.PutUint64(key[2:], idx)
|
||||
|
||||
return key
|
||||
|
|
@ -483,9 +483,9 @@ func (s *DbStore) ReIndex() {
|
|||
oldCntKey[0] = keyDistanceCnt
|
||||
newCntKey[0] = keyDistanceCnt
|
||||
key[0] = keyData
|
||||
key[1] = byte(s.po(Key(key[1:])))
|
||||
key[1] = s.po(Key(key[1:]))
|
||||
oldCntKey[1] = key[1]
|
||||
newCntKey[1] = byte(s.po(Key(newKey[1:])))
|
||||
newCntKey[1] = s.po(Key(newKey[1:]))
|
||||
copy(newKey[2:], key[1:])
|
||||
newValue := append(hash, data...)
|
||||
|
||||
|
|
@ -760,7 +760,7 @@ func (s *DbStore) SyncIterator(since uint64, until uint64, po uint8, f func(Key,
|
|||
|
||||
for ok := it.Seek(sincekey); ok; ok = it.Next() {
|
||||
dbkey := it.Key()
|
||||
if dbkey[0] != keyData || dbkey[1] != byte(po) || bytes.Compare(untilkey, dbkey) < 0 {
|
||||
if dbkey[0] != keyData || dbkey[1] != po || bytes.Compare(untilkey, dbkey) < 0 {
|
||||
break
|
||||
}
|
||||
key := make([]byte, 32)
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func Proximity(one, other []byte) (ret int) {
|
|||
m = MaxPO % 8
|
||||
}
|
||||
for j := 0; j < m; j++ {
|
||||
if (uint8(oxo)>>uint8(7-j))&0x01 != 0 {
|
||||
if (oxo>>uint8(7-j))&0x01 != 0 {
|
||||
return i*8 + j
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue